fork download
  1. import re
  2.  
  3. content = 'Should replace [obj[text]obj] inside [loc[brackets]loc]'
  4. pattern = re.compile(r"\[([A-Za-z0-9]+)(\[(.*?)\])([A-Za-z0-9]+)\]")
  5. new = re.sub(pattern, r'[\1xxx\4]', content);
  6. print(new)
Success #stdin #stdout 0.03s 9568KB
stdin
Standard input is empty
stdout
Should replace [objxxxobj] inside [locxxxloc]