728x90
반응형
re.search로 찾은 문자열을 그대로 re.sub를 이용해서 삭제하고 싶었다.
parentheses = re.search('\([\w|\W]*:[\w|\W]*\)', words)
if parentheses:
words = re.sub(f"\({parentheses.group()}\)", '', words)
re.error: missing ), unterminated subpattern at position 2
re.search안에서 escape 문자가 포함된 경우 에러가 난다.
난 찾아낸 문자열 그대로를 삭제하고 싶기 때문에, 이를 escape 처리하는 문구를 넣어 주자.
parentheses = re.search('\([\w|\W]*:[\w|\W]*\)', words)
if parentheses:
words = re.sub(re.escape(parentheses.group()), '', words)
728x90
반응형
'내가 마주친 에러' 카테고리의 다른 글
class 불일치 에러 (0) | 2024.12.02 |
---|---|
csv파일이 너무 클 때 python 에러 (1) | 2024.11.08 |
허깅페이스 request error (0) | 2024.10.22 |
lipiji/TranSummar github코드 파라미터 관련 (0) | 2022.10.20 |
CRF import 할때 생기는 에러 (0) | 2022.06.15 |
댓글