import re
p = re.compile(r'\[{2}(?:[^|\]]*\|)?([^]]*)]{2}')
test_str = "He lives in [[Gimhae city|Gimhae]]. He lives in [[Gimhae]]. "
result = re.sub(p, r"\1", test_str)
print(result)