Not a problem. Replace the "\d+" with ".+?"
Here's the modified regex in action: find anything enclosed in brackets
To explain, \d matches any digit, and the + means "one or more". So \d+ matches any series of digits, AKA a number.
In the new pattern, the . matches anything (except newlines), + means the same thing (one or more) and the "?" in this context means...
User Profile
Collapse
-
No problem, happy to help. :)
Pardon the self-promotion, but I have a site you might find useful for your future regex endeavors: Regex Storm.
It runs on the .NET regex engine, and I tried to cater it to programmers like us that need to come up with regex to use in our code.Leave a comment:
-
No worries, here's a code snippet for you:
Basically, we instantiate a new Regex object with the pattern we want to...Code:Regex r = new Regex(@"(?<=\[)\d+(?=\])"); MatchCollection mc = r.Matches("434623[73899]256[346]37856[3634][367][8922] 45745[12954]35478"); foreach (Match m in mc) { string s = m.Value; }Leave a comment:
-
Well, here's the regex way. :)
Try this regex pattern: (?<=\[)\d+(?=\])
The numbers you want will be in the collection of matches you get from the result.
You can see it in action here: http://regexstorm.net/Tester.aspx?p=...b12954%5d35478Leave a comment:
No activity results to display
Show More
Leave a comment: