Reputation: 503
I want to find number with don't proceed with £ character. Say I have a string:
"Gross Domestic Product in 2012 was £127 billion"
I want to return 2012 only.
I ve tried [^$][0-9]*
but this only ignores $
character. Tried to match the whole word which starts and ends with number \b[0-9]*\b
but \b
applies only to [0-9a-zA-Z]
Any more suggestions?
Upvotes: 3
Views: 6218
Reputation: 12582
This is a good tool where you can try those out. Here is a sample way to do what you asked http://regex101.com/r/iH9uS8
Upvotes: 1
Reputation: 2736
You can prefix your string with space and search for the regex \s[0-9]+
wich would mean 'digital prefix of word, starting with digit' This will exclude all words starting with $, £ or everything else except digit.
Upvotes: 1
Reputation: 20616
One option which works (as tested using http://gskinner.com/RegExr) is:
(?<![£0-9])[0-9]+
This uses negative lookbehind to exclude £. The additional exclusion of 0-9 is to prevent it finding "27" in the above in addition to the "2012".
Upvotes: 4