fork download
  1. import re
  2. s = '''02/58 98
  3. 02/58 /98
  4. 02/58 9518
  5. 02/58 /98'''
  6.  
  7. print(re.sub(r'(\d{1,2}/\d{1,2}) /?(?:(\d{4}|\d{2}))', r'\g<1>/\g<2>', s))
Success #stdin #stdout 0.02s 27720KB
stdin
Standard input is empty
stdout
02/58/98
02/58/98
02/58/9518
02/58/98