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