fork download
  1. import re
  2. def cleanse_no(s):
  3. regex = r"(?<!\S)\d{2}(?=,?(?:\s|$))"
  4. return ", ".join(re.findall(regex, s))
  5.  
  6. test_digits = ["€ 22.22", ". 23,600.90", "25 45 61", "22, 232, 36, 02,", "1, 23, 456"]
  7. for test_dgt in test_digits:
  8. print(test_dgt,"-------find_no--------->",cleanse_no(test_dgt))
Success #stdin #stdout 0.02s 27728KB
stdin
Standard input is empty
stdout
€ 22.22 -------find_no---------> 
. 23,600.90 -------find_no---------> 
25 45 61 -------find_no---------> 25, 45, 61
22, 232, 36, 02, -------find_no---------> 22, 36, 02
1, 23, 456 -------find_no---------> 23