Regex not working to replace urls

I’m trying to remove some urls in html. The regex is working fine in Patterns:

But in my code the urls are not removed:

if theHtml = "" then Return ""

dim theRegex as new RegEx
theRegex.Options.TreatTargetAsOneLine = True
theRegex.Options.CaseSensitive = False
theRegex.Options.DotMatchAll = True
theRegex.Options.ReplaceAllMatches = True

dim SearchPattern as String = "url\((""(https?://[^""]+)"")\)"
theRegex.Options.Greedy = True
theHtml = theRegex.Replace(theHtml)
'dim m as RegExMatch = theRegex.Search(theHtml)

What am I doing wrong?

Example:

regex.xojo_xml_project.zip (4.4 KB)

1 Like

@Kem_Tekinay will know when he comes online.

2 Likes
Protected Function FixHtml(theHtml as String) As String
  
  if theHtml = "" then Return ""
  
  Dim rx As New RegEx
  rx.SearchPattern = "(?si-Um)url\((""(https?://[^""]+)"")\)"
  rx.ReplacementPattern = "REPLACED_URL"
  
  Dim rxOptions As RegExOptions = rx.Options
  rxOptions.ReplaceAllMatches = True
  
  Return rx.Replace( theHtml )
  
End Function

Done with RegExRX by @Kem_Tekinay :wink:

2 Likes

Thanks! I think I foobared the example and then looked too often at the code.

I forgot the line:
theRegex.SearchPattern = SearchPattern

Time to get off the computer.

1 Like

He may be already dreaming the answer :innocent:

1 Like

That’ll do it. :slight_smile:

1 Like

BTW: Still waiting for an ARM Version of RegExRX on macOS. :wink:

1 Like

Look’s like a Universal Binary. Nice! Thank you :slight_smile:

1 Like