Hi friends i was in need of a regex which will return only 25,36,30 for me from
25 10a 36 10b 30
as they are the only pure numbers in the sequence.
I tried this but it did not work for me :
(^|[ ])\d+|($|[ ])
Any suggestions?
Hi friends i was in need of a regex which will return only 25,36,30 for me from
25 10a 36 10b 30
as they are the only pure numbers in the sequence.
I tried this but it did not work for me :
(^|[ ])\d+|($|[ ])
Any suggestions?
Noticing your multiple regex questions might I suggest some educational reading. Regular-Expressions.info has some great tutorials for getting acquainted with RegEx.
You could use the word boundary option:
\b(\d+)\b
but some punctuation characters will be marked as a word boundary so this won't give what you want.
So it looks like you'll have to explicitly look for whitespace:
/(^|\s+)(\d+)(\s+|$)/
When extracting the number remember to get the second group as the first will only have spaces in it.
\d+
is all you need. If you're using C#, note the difference between 'Match' and 'Matches' on the Regex
object. One finds a single match, the other finds multiple non-overlapping matches.
http://msdn.microsoft.com/en-us/library/30wbz966(VS.71).aspx