Your regex does not match the strings you showed. You can use
\b5 Months[\s\S]*?(\d+(?:\.\d+)?)
See the regex demo. Details:
\b
– a word boundary5 Months
– a literal text[\s\S]*?
– any 0 or more chars, as few as possible(\d+(?:\.\d+)?)
– Capturing group 1: one or more digits followed with an optional sequence of a.
and one or more digits.
Test run in VBA:
Sub TestFn()
Dim reg4 As Object: Set reg4 = CreateObject("vbscript.regexp")
reg4.Pattern = "\b5 Months[\s\S]*?(\d+(?:\.\d+)?)"
Dim myText As String
myText = "5 Months" & vbCrLf & vbCrLf & "0.00"
Dim MCS As Object
Set MCS = reg4.Execute(myText)
Dim Months5 As String: Months5 = MCS(0).SubMatches(0)
Debug.Print (Months5)
End Sub
CLICK HERE to find out more related problems solutions.