fork download
  1. import re
  2.  
  3. strings = [
  4. "Total Return Transportation $16.01",
  5. "Total Return Transportation $123,899,116.01",
  6. "Total Return Transportation $1612.01"
  7. ]
  8.  
  9. pattern = r"\A(Total) (\w+) (\w+) (\$\d{1,3}(?:,\d{3})*(?:\.\d+)?)(?!\S)"
  10.  
  11. for s in strings:
  12. match = re.match(pattern, s)
  13. if match:
  14. print(match.group(4))
  15.  
Success #stdin #stdout 0.02s 9624KB
stdin
Standard input is empty
stdout
$16.01
$123,899,116.01