RegEx object pattern .*? seems to be greedy when followed by \(
Think this greedy behavior begain in 25.8.(2, 3 or 4) and is also present in 26.2.1
Here is an example macro:
Public Sub Main()
html = "a-percent"">(+2.57%) another-percent"">(-0.75%)"
Dim regEx As Object
Set regEx = CreateObject("VBScript.RegExp")
regEx.Global = False
regEx.IgnoreCase = True
' Works as expected
regEx.Pattern = "percent"".*?(\-?[0-9,]+(?:\.[0-9]+)?)\%\)"
Set Matches = regEx.Execute(html)
If Matches.Count > 0 Then
msgbox(Matches.Item(0))
Percent = Replace(Matches.Item(0).SubMatches.Item(0), ",", "")
msgbox(Percent)
End If
' Does not work as expected... .*? seems to be greedy when followed by \(
regEx.Pattern = "percent"".*?\((\-?[0-9,]+(?:\.[0-9]+)?)\%\)"
Set Matches = regEx.Execute(html)
If Matches.Count > 0 Then
msgbox(Matches.Item(0))
Percent = Replace(Matches.Item(0).SubMatches.Item(0), ",", "")
msgbox(Percent)
End If
End Sub