Return the string obtained by replacing the leftmost
non-overlapping occurrences of the pattern in string by the
replacement repl. repl can be either a string or a callable;
if a string, backslash escapes in it are processed. If it is
a callable, it's passed the match object and must return
a replacement string to be used.
>>> 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.sub()
无法接受re.IGNORECASE
。在文件规定:
但是,使用此方法可以代替它:
模块级sub()调用在末尾不接受修饰符。这是“count”参数-要替换的模式出现的最大数量。在
对于regex标志(
IGNORECASE, MULTILINE, DOTALL
),在re.sub
中没有函数参数。在备选方案:
^{pr2}$EditPython3.1增加了对regex标志http://docs.python.org/3.1/whatsnew/3.1.html的支持。从3.1开始,例如^{} 的签名如下:
相关问题 更多 >
编程相关推荐