I'm kinda rusty at regular expressions, but something like this should match it. "[0-9]+" It may need to get more complex depending on how the string is.
Sorry I should have said but it is in the middle of other stuff as well, so the string will look like,
"This is some text <<789798>> and I need that number!"
That actually still works for this. If there are other numbers in the string that don't have the "<< >>" then that could present some issues. If that's the case, "<+[0-9]+>+" this will find the entire string like this "<<898989>>" and then maybe a subsequent "[0-9]+" on that would get the number in the middle. Someone that's good at regex's could probably craft a way to get just the number in one step -- obviously, that someone isn't me
Apparently all you have to do is group them using parenthesis, then pull out the matches using the Groups collection of the match. The Groups collection appears to go like this:
0 - Returns the Whole expression
1 - Returns the first sub-expression
2 - Returns the second sub-expression
and so on...
This does what you want.
Visual Basic:
Dim source As String = "(<{2})([0-9]+)(>{2})"
Dim s As String = "Hello world <<898989>> hello world "
Dim reg As New Regex(source)
Dim r As String
r = reg.Match(s, source).Groups(2).Value
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.