fork(1) download
  1. import re
  2. strs = ['Some $ 10 here',
  3. 'And 10$ here',
  4. 'And 10 $ here',
  5. 'And 1000005 dollars here',
  6. 'And dollars one million and five here']
  7. r_dollar = r'(?:\$(?:usd)?|(?:dollar|buck)s?)' # USD dollar name
  8. r_textnumber = r'\b(?!\s)(?:[\sa-]|zero|one|tw(?:elve|enty|o)|th(?:irt(?:een|y)|ree)|fi(?:ft(?:een|y)|ve)|(?:four|six|seven|nine)(?:teen|ty)?|eight(?:een|y)?|ten|eleven|forty|hundred|thousand|[mb]illion|and)+\b(?<!\s)'
  9. r_number = r'(?:[1-9][0-9]+|{})'.format(r_textnumber) # Dollar amount
  10. valuta_with_num = r'{0}\s?{1}|{1}\s?{0}'.format(r_number, r_dollar) # Main regex
  11. currency_tags = re.compile(valuta_with_num)
  12.  
  13. for s in strs:
  14. print(currency_tags.findall(s))
  15.  
Success #stdin #stdout 0.02s 27712KB
stdin
Standard input is empty
stdout
['$ 10']
['10$']
['10 $']
['1000005 dollars']
['dollars one million and five']