mercredi 18 septembre 2019

How can I adapt a regex pattern for VBA

I am trying to remove a specific string of text using regex and have the following which works on regex101.com however i understand that VBA has some nuances when using regex and the pattern i have doesn't seem to work at all.

the pattern which i validated is in the code below, If possible i would also like to combine it with the below (designed to remove html tags) "\<.*?>" this does work but i currently run a separate regex.replace function to remove this.

Dim regEx As Object , str As String
Set regEx = CreateObject("VBScript.RegExp")

With regEx
  '.Pattern = "<a\b([^>""']|""[^""]*""|'[^']*')+class=""changed-by"">.*?<\/a>"
'.pattern = "\<.*?\>" ' this is the second pattern i use to remove html tages which works
  .Global = True 'If False, would replace only first
  .IgnoreCase = False
  .MultiLine = False
End With

str = some text here <a href="/instrument/2014/36.pdf" target="_blank" title="2014/36 - 01/07/2014" class="changed-by">1</a> some text here
Debug.Print regEx.Replace(str, "")

Aucun commentaire:

Enregistrer un commentaire