fork download
  1. import re
  2. p = re.compile(r'\[{2}(?:[^|\]]*\|)?([^]]*)]{2}')
  3. test_str = "He lives in [[Gimhae city|Gimhae]]. He lives in [[Gimhae]]. "
  4. result = re.sub(p, r"\1", test_str)
  5. print(result)
Success #stdin #stdout 0.01s 8968KB
stdin
Standard input is empty
stdout
He lives in Gimhae. He lives in Gimhae.