fork download
  1. import re
  2. rx = re.compile(r"(\d+(?:-\d+)?\+?)\s*(years?)", re.I)
  3. strs = ["10+ years", "10 years", "1 year", "10-15 years"]
  4. for description in strs:
  5. exp_temp = rx.search(description)
  6. if exp_temp:
  7. print(exp_temp.groups())
Success #stdin #stdout 0.02s 27712KB
stdin
Standard input is empty
stdout
('10+', 'years')
('10', 'years')
('1', 'year')
('10-15', 'years')