로딩
요청 처리 중입니다...

[파이썬] 한번에 여러개 문자열 치환기

 [파이썬] 한번에 여러개 문자열 치환기

한번에 하나씩 치환하는 것이 아닌 지정된 모든 문자열을 한번에 치환해 주는 함수이다. replacements 에 치환을 원하는 문자들을 정리해주고 함수를 호출하면 한번에 치환해서 반환해준다. def mreplace(text, replacements): regex = re.compile("|".join(map(re.escape, replacements.keys())), re.IGNORECASE) def rmatch(match): return replacements[match.group(0).lower()] return regex.sub(rmatch, text) #치환 문자열 replacements = { "": "\n", "": "\n", "": "\n", "": "\n", "<":"[", ">":"]", } content = mreplace(content, replacements)...