fork download
  1. import re
  2.  
  3. def extract_values(sentence):
  4. num = r'\d*\.?\d+(?:/\d*\.?\d+)*'
  5. return re.findall(fr'{num}(?:\s+(?:and|to)\s+{num})*', sentence)
  6.  
  7. print(extract_values("He is 1 and 1/2 years old. He is .5 years old and he is 5 years old. He is between 9 to 11 or 9 to 9 and 1/2. He was born 11/12/20"))
  8.  
Success #stdin #stdout 0.03s 9452KB
stdin
Standard input is empty
stdout
['1 and 1/2', '.5', '5', '9 to 11', '9 to 9 and 1/2', '11/12/20']