fork(5) download
  1. import re
  2. text = '''5.3 x 2.5 cm
  3. 11 x 11 mm
  4. 7 mm
  5. 13 x 12 x 14 mm
  6. 13x12cm'''
  7. x = "(?:\.\d{1,2}|\d{1,4}\.?\d{0,2}|\d{5}\.?\d?|\d{6}\.?)"
  8. by = "(?: )?(?:by|x)(?: )?"
  9. cm = "(?:mm|cm|millimeter|centimeter|millimeters|centimeters)"
  10. x_cm = "(?:" + x + " *(?:to|\-) *" + cm + "|" + x + cm + ")"
  11. xy_cm = "(?:" + x + cm + by + x + cm +"|" + x + by + x + cm +"|" + x + cm + by + x +"|" + x + by + x + ")"
  12. xyz_cm = "(?:" + x + cm + by + x + cm + by + x + cm + "|" + x + by + x + by + x + cm + "|" + x + by + x + by + x + ")"
  13. m = "{}|{}|{}".format(xyz_cm, xy_cm, x_cm)
  14. a = re.compile(m)
  15. print a.findall(text)
  16.  
Success #stdin #stdout 0.01s 23352KB
stdin
Standard input is empty
stdout
['5.3 x 2.5', '11 x 11', '13 x 12 x 14', '13x12cm']