fork download
  1. import re
  2. num = fr"""(\d\d)([A-Z])?"""
  3. sep = fr"""and |or |, """
  4.  
  5. #pattern composition
  6. pattern = fr"""{num}(?:\s*(?:{sep})\s*{num})*"""
  7.  
  8. text= """biscuits 10 are good
  9. biscuits 20 and 30 are good
  10. biscuits 40 and hot dog are good
  11. but this one 50A and 50B and not ok"""
  12.  
  13. refs = re.finditer(pattern, text, re.VERBOSE,)
  14. for ref in refs:
  15. TEXT = ref.group()
  16. print(TEXT)
  17.  
Success #stdin #stdout 0.03s 9472KB
stdin
Standard input is empty
stdout
10
20 and 30
40
50A and 50B