Reputation: 877
I have a string below, I would like to extract number (12,000) from TOTAL but not from CLIENT SUB-TOTAL
CLIENT SUB-TOTAL : 12,000 12,000
------------ ------------ ------------ ------------
TOTAL : 12,000 12,000
I have tried with the following regex, but it still matches 2 group.
(?:TOTAL : )([0-9]+[,]+[0-9]+)
Thank you for your help
Upvotes: 1
Views: 968
Reputation: 163447
You don't need the non capture group (?:
in the pattern that you tried as you are matching the text only.
Also not that you don't need the square brackets here [,]+
and due to the +
it could possibly also match ,,,,
What you might do is assert a whitespace boundary to the left if a negative lookbehind is supported, and instead of hardcoding the exact amount of spaces, match 1 or more whitespace chars without a newline using [^\S\r\n]+
(?<!\S)TOTAL[^\S\r\n]+:[^\S\r\n]+([0-9]+,[0-9]+)\b
Upvotes: 1
Reputation: 110342
You could try doing a negative assertion that TOTAL
isn't preceded by a dash. Something like the following would work:
Upvotes: 1