-
Regex help
Hi Guys,
I am trying to use a regular expression to find a certain string within a textbox.
Is it possible to include the equals sign (=) within the regex so it looks for this? When i type the equals sign within the regex it doesn't fnid it any more.
Works when searching this string - "and JobID 816138</Detail>":
Code:
Dim MatchJobId As System.Text.RegularExpressions.MatchCollection = System.Text.RegularExpressions.Regex.Matches(MyResults, "(?<=and JobID ).+?(?=</Detail>)", System.Text.RegularExpressions.RegexOptions.Singleline)
Don't Work when searching "?JobID=816138</Detail>":
Code:
Dim MatchJobId As System.Text.RegularExpressions.MatchCollection = System.Text.RegularExpressions.Regex.Matches(MyResults, "(?<=?JobID=).+?(?=</Detail>)", System.Text.RegularExpressions.RegexOptions.Singleline)
Do i have to use different characters for the = and ? sign when they are being included within the regex search?
Thanks,
Chloe ~X~
-
Re: Regex help
I think you'll need to use the bar (\) for those chars...
-
Re: Regex help
did that help?
the \ character is an escape character
-
Re: Regex help
have a look there : http://msdn.microsoft.com/en-us/library/1400241x%28VS.85%29.aspx It was very helpful to me when I had to work with regular expressions.
The "=" character is used for Positive lookahead so escaping it with the backslash character as previously suggested should work for that.
Your problem might also come from the "?" character which is a Metacharacter