我用re.sub发现了这个有趣的问题:
import re
s = "This: is: a: string:"
print re.sub(r'\:', r'_', s, re.IGNORECASE)
>>>> This_ is_ a: string:
Run Code Online (Sandbox Code Playgroud)
注意如何只替换前两个实例.似乎为标志添加[implicit]参数名称可以解决问题.
import re
s = "This: is: a: string:"
print re.sub(r'\:', r'_', s, flags=re.IGNORECASE)
>>>> This_ is_ a_ string_
Run Code Online (Sandbox Code Playgroud)
我想知道是否有人可以解释它或它实际上是一个错误.
我之前遇到过这个问题,但缺少参数名称,string但从来没有因为flags字符串它通常会爆炸.
什么是最好的.htaccess配置,只允许美国用户访问网站?
我似乎无法找到涵盖所有IPV4和IPV6用户的明确答案.