[Python] re.sub에서 특정한 것만 바꾸고 싶을 때 하는 방법

2020. 8. 26. 23:19분석 Python/구현 및 자료

전처리 앞으로 해야 할 것이 더 많지만, 일단 찾은 것까지만 기록해보고자 한다.

 

import re
string = '@@He11o Wor1d!'
string = re.sub(r'([a-zA-Z])[@31!]+(?=[a-zA-Z])', r'\1', string)
string

string = 'n"t'
re.sub(r'([a-zA-Z])"(?=[a-zA-Z])',r"\1'",string)

string = '4"t'
re.sub(r'([a-zA-Z1-9])"(?=[a-zA-Z])',r"\1'",string)

 

string = 'n" '
re.sub(r'([a-zA-Z])" ',r"\1",string)

'n'

string = ' "nL'
re.sub(r'\s"([a-zA-Z]{2,})', r" \1",string)

' nL'

string = '""ADASDASD""'
re.sub(r'""', r'"',string)

'"ADASDASD"'

 

 

https://stackoverflow.com/questions/47038551/removing-symbols-between-letters-python

 

Removing symbols between letters Python

I would like to remove certain symbols from a string. I only want to remove symbols that are between letters. If my question wasn't clear enough then here are some examples: symbols are @31! Input...

stackoverflow.com

https://stackoverflow.com/questions/10660435/pythonic-way-to-create-a-long-multi-line-string?rq=1

 

Pythonic way to create a long multi-line string

I have a very long query. I would like to split it in several lines in Python. A way to do it in JavaScript would be using several sentences and joining them with a + operator (I know, maybe it's n...

stackoverflow.com

 

728x90