fork download
  1. import re
  2.  
  3. TEXT_SAMPLE = "30feet is about 10metre but that's 1 rough estimate several numbers are like 2, 137, and 40 or something big numbers are like 2,137,040 or something"
  4.  
  5. def extract_numbers(text):
  6. return [float(x.replace(',','')) for x in re.findall(r'\b\d{1,3}(?:,\d{3})*(?:\.\d+)?(?!\d)', text)]
  7.  
  8. print(extract_numbers(TEXT_SAMPLE))
Success #stdin #stdout 0.02s 9600KB
stdin
Standard input is empty
stdout
[30.0, 10.0, 1.0, 2.0, 137.0, 40.0, 2137040.0]