Regular Expression Help in .NET
Posted
by Matt H.
on Stack Overflow
See other posts from Stack Overflow
or by Matt H.
Published on 2010-04-08T21:30:06Z
Indexed on
2010/04/08
21:33 UTC
Read the original article
Hit count: 355
I have a simple pattern I am trying to match, any characters captured between parenthesis at the end of an HTML paragraph. I am running into trouble any time there is additional parentheticals in that paragraph:
i.e.
If the input string is "..... (321)</p>" i want to get the value (321)
However, if the paragraph has this text: "... (123) (321)</p>" my regex is returning "(123) (321)" (everything between the opening "(" and closing ")"
I am using the regex pattern "\s(.+)</p>"
How can I grab the correct value (using VB.NET)
This is what I'm doing so far:
Dim reg As New Regex("\s\(.+\)</P>", RegexOptions.IgnoreCase)
Dim matchC As MatchCollection = reg.Matches(su.Question)
If matchC.Count > 0 Then
Dim lastMatch As Match = matchC(matchC.Count - 1)
Dim DesiredValue As String = lastMatch.Value
End If
© Stack Overflow or respective owner