fork(1) download
  1. import re
  2.  
  3. text = '''C 1
  4. D 2.2
  5. Y 1
  6. Z 2.2'''
  7.  
  8. for s in text.splitlines():
  9. print("--- '" + s + "' ---")
  10. m = re.search(r'((C|Y) (\d)|(D|Z) (\d)\.(?:\d))', s)
  11. if m and m.group(2):
  12. print(m.group(3))
  13. elif m and m.group(4):
  14. print(m.group(5))
  15. else:
  16. print("NO MATCH!")
Success #stdin #stdout 0.02s 9572KB
stdin
Standard input is empty
stdout
--- 'C 1' ---
1
--- 'D 2.2' ---
2
--- 'Y 1' ---
1
--- 'Z 2.2' ---
2