fork download
  1. import re
  2.  
  3. texts = [
  4. "The measurements are (w x h x l): 5x7x3cm", # => [(w,h,l)]
  5. "Measurement options are (wxhxl), (hxlxb): Some random stuff", # => [(w,h,l),(h,l,b)]
  6. "The measurements, in form wxhxl: 5x7x3cm" # => [(w,h,l)]
  7. ]
  8. for text in texts:
  9. print( [tuple(''.join(x.split()).split('x')) for x in re.findall(r'\b[whlb](?:\s*x\s*[whlb])+\b', text)] )
Success #stdin #stdout 0.03s 9388KB
stdin
Standard input is empty
stdout
[('w', 'h', 'l')]
[('w', 'h', 'l'), ('h', 'l', 'b')]
[('w', 'h', 'l')]