This step is teensy tiny, but is so important that it must be pointed out. I added a backslash question mark (\?) to the pattern. This is important to note because a normal question mark has a special meaning to RegEX. So, when you actually are looking for a question mark in your text, you must escape it. The backslash is the RegEX character for escaping the character that immediately follows. So, when we match on "\?", we are really just matching on "?". Get it? This is VERY important.
Option Explicit
Dim myFakeEmail: myFakeEmail = "" & _
"I never received a response from anyone about my inquiry. Never spoke" & vbNewLine & _
"with Scala Re[. Don't remember any correspondence. I wanted to know" & vbNewLine & _
"the price of the software." & vbNewLine & _
"" & vbNewLine & _
"-----Original Message-----" & vbNewLine & _
"From: Scala Sales [mailto:Someone@Scala.com]" & vbNewLine & _
"Sent: Thursday, July 01, 2004 9:05 AM" & vbNewLine & _
"To: Prospect" & vbNewLine & _
"Subject: RE: Company, State, Country" & vbNewLine & _
"" & vbNewLine & _
"Prospect," & vbNewLine & _
"" & vbNewLine & _
"We have noticed the last update to your discussion with Scala Rep" & vbNewLine & _
"regarding ""Company, State, Country"" was 7 days ago. If you" & vbNewLine & _
"like, you can follow the included link..." & vbNewLine & _
"" & vbNewLine & _
"http://www.scala.com/message/?59483475213687" & vbNewLine & _
"" & vbNewLine & _
" ...and log in with the email address noone@nowhwere.com to" & vbNewLine & _
"let us know how your endeavors are proceeding. You can also reach" & vbNewLine & _
"Scala Rep by telephone at (555) 123-4567." & vbNewLine & _
"" & vbNewLine & _
"Regards," & vbNewLine & _
"" & vbNewLine & _
"Scala Sales" & vbNewLine & _
""
WScript.Echo(FindMessageID(myFakeEmail))
Function FindMessageID(messageBody)
Dim MyRegEx
Set MyRegEx = New RegExp
MyRegEx.IgnoreCase = True
MyRegEx.Global = True
MyRegEx.Pattern = "http://www.scala.com/message/\?"
Dim testMatch: testMatch = MyRegEx.Test(messageBody)
If testMatch = True Then
Dim myMatches: Set myMatches = MyRegEx.Execute(messageBody)
Dim firstMatch: Set firstMatch = myMatches(0)
FindMessageID = firstMatch.Value
Else
FindMessageID = ""
End If
Set firstMatch = Nothing
Set myMatches = Nothing
Set MyRegEx = Nothing
End Function
|
And our output proves that the question mark is now included in the matched pattern...
|