>>> help(re.sub)
1 Help on function sub in module re:
2
3 sub(pattern, repl, string, count=0)
4 Return the string obtained by replacing the leftmost
5 non-overlapping occurrences of the pattern in string by the
6 replacement repl. repl can be either a string or a callable;
7 if a callable, it's passed the match object and must return
8 a replacement string to be used.
더 기능이 없습니다 매개 변수는 re.compile
같이 정규식 플래그 (IGNORECASE, MULTILINE, DOTALL
)의 경우 re.sub
입니다.
대안 :
>>> re.sub("[M|m]r", "", "Mr Bean")
' Bean'
>>> re.sub("(?i)mr", "", "Mr Bean")
' Bean'
편집 파이썬 3.1, http://docs.python.org/3.1/whatsnew/3.1.html 정규식 플래그에 대한 지원을 추가했습니다. 3.1부터는 예를 들어 정규식 모드를 설정하는 플래그를하지 않습니다()
re.sub(pattern, repl, string[, count])
의 re.sub : 파이썬 2.6.4 문서에서
re.sub(pattern, repl, string[, count, flags])