생물정보학/Python Study

Python 정규표현식으로 치환하기

케이든 2016. 3. 10. 09:58


Python 정규표현식으로 치환하기


정규표현식을 사용하기 위한 re module 수입 ㅋ


import re


#re.sub("치환할 정규표현식", "새로 치환될 문자", "치환할 정규표현식이 포함된 문자열")

re.sub('\s+', '_', "This should be connected")


# This_should_be_connected


"This should be connected" 이 문자열의 공백이 "_"으로 치환되어 "This_should_be_connected" 이렇게 나온다.