I'm trying to come up with a regex for dollar value search in Python. I have looked and tried lots of solutions on SO posts, but none of them is quite working.
The regex I came up with is:
[Ss] # OCR will mess up with dollar signs, so I'm specifically looking for S and s as the starting of what I'm looking for
\d+ # any digits to start off
(,\d{3})* # include comma for thousand splits, can have multiple commas
(.\d{2})? # include dot and 2 decimals, but only one occurrence of this part
I have tried this on the following example:
t = "sixteen thousand three hundred and thirty dollars (s16,330.00)"
r = "[Ss]\d+(,\d{3})*(.\d{2})?"
re.findall(pattern=r, string=t)
And I got:
[(',330', '.00')]
Regex doc says that:
If one or more groups are present in the pattern, return a list of groups; this will be a list of tuples if the pattern has more than one group. Empty matches are included in the result.
But it is not even getting the whole number part.
My question is: I really want to find s16,330.00
as a single piece. Is there a solution?