fork download
  1. import re
  2. text = """ID Information
  3.  
  4. 1 :20:Test1 :25:test2:28C:test3"""
  5.  
  6. valid_line_rx = r'^(\d+\s*)(:\d{2}[A-Za-z]?:.*)'
  7. print( re.sub(valid_line_rx, lambda m:
  8. "\n".join(["{}{}".format(m.group(1),x) for x in re.split(r'(?!^)(?=:\d{2}[A-Za-z]?:)', m.group(2))]),
  9. text,
  10. flags=re.M)
  11. )
Success #stdin #stdout 0.03s 9756KB
stdin
Standard input is empty
stdout
ID        Information

1         :20:Test1  
1         :25:test2
1         :28C:test3