파이썬 특수문자 제거 질문드립니다.
조회수 1007회
pattern='[\W]'
text = re.sub(pattern, ' ', text)
이 부분에서 저는 isn't aren't it's 에서와 같이 '는 제거하고싶지 않은데 어떻게 할 수 있을까요?ㅠㅠ
1 답변
-
정규표현식만으로는 해결이 안 될듯..
import re text = "fd-sf+1%2'fd4't&y'y67" text2 = '' pattern='[\W]' for i in range(len(text)): if re.match("'",text[i]): text2 = text2 + text[i] continue text2 = text2 + re.sub(pattern, ' ', text[i])
>>> text2 "fd sf 1 2'fd4't y'y67"
-
(•́ ✖ •̀)
알 수 없는 사용자
-
댓글 입력