fork download
  1. import re
  2.  
  3. pattern = r"\[.*?\]|(\d+)"
  4.  
  5. s = "[Verse 1: Bankroll Fresh] Dope boy, '[9]5 Air Max on Came from 1952.."
  6.  
  7. print(re.sub(pattern, lambda x: '' if x.group(1) else x.group(), s))
  8.  
  9. print(re.sub(r'\[?\D*(\d+)\D*\]?', lambda x: x.group(0) if x.group(0).startswith('[') else x.group(1), s))
  10.  
Success #stdin #stdout 0.04s 9460KB
stdin
Standard input is empty
stdout
[Verse 1: Bankroll Fresh] Dope boy, '[9] Air Max on Came from ..
[Verse 1: Bankroll Fresh] Dope boy, '[951952