小编dwk*_*wkd的帖子

re.sub只替换前两个实例

我用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字符串它通常会爆炸.

python regex string replace

4
推荐指数
1
解决办法
602
查看次数

仅允许美国用户访问网站

什么是最好的.htaccess配置,只允许美国用户访问网站?

我似乎无法找到涵盖所有IPV4和IPV6用户的明确答案.

apache .htaccess

3
推荐指数
1
解决办法
601
查看次数

标签 统计

.htaccess ×1

apache ×1

python ×1

regex ×1

replace ×1

string ×1