Reputation: 183
I have a text :
Revenue: $12.9 billion
Regex=====>Revenue\W+(\$*\s*\d+\s*(\.\s*\d+)*)\s*billion
Now I want $12.9 in a specific group but by using \W+ it takes ": $" after revenue. So I want to write such regex that it will consider all nonalphanumeric character except "$"
How can I do that???
Upvotes: 0
Views: 87
Reputation: 11116
Revenue[^\w$]+(.\s*\d+\s*(\.\s*\d+))\s*billion
use this,
the .
will match the unmatched $
demo here : http://regex101.com/r/aQ8qP7
$12.9
is captured in the first group
Upvotes: 0
Reputation: 149020
A character class like [^\w$]
will match anything that is not a word character or $
. Also, there's no need to have \s*
twice together, or to have it appear after \W+
(or [^\w$]+
) because the preceding character class will swallow up any whitespace characters anyway:
Revenue[^\w$]+(\d+\s*(\.\s*\d+))\s*billion
Upvotes: 1