How to write regex that can 1.
match currency which may or may not include a comma or decimal and 2.
match the currency code only. What I see is mostly matching currency symbols.
I want to be able to match currency ['300,000.00']
and currency code ['USD']
from a complete text such as this:
Userid 9XXXX219 sales USD300,000.00 On 01-JUL-2016 08:34:32
So far I tried this but it matches only the ones with decimal, not the ones without decimal or the ones with comma:
s = 'USD1 USD1.00 USD100.00 USD1,000 CAD1,000.00'
re.findall(r'\d+\.\d+', s)
#matches
['1.00', '100.00', '000.00']
#should not match any other thing e.g. 1XXXX324
#instead of this:
['1','1.00', '100.00', '1,000', '1,000.00']
And how to write another regex pattern to match ONLY currency codes? i.e.
['USD', 'USD', 'USD', 'USD','CAD']