我想匹配以下字符串:
strings = iamcool.iplay=ball?end
我想删除从“.”开始一直到“?”的项目,所以我想删除 .iplay=ball
,所以我应该有 iamcool?end
这是我的正则表达式:
print re.sub(r'\.\.*?','', strings)
我不知道如何在“?”处停止
最佳答案
使用否定字符类[^?]
,它匹配除?
之外的任何内容。
>>> re.sub(r'\.[^?]*', '', strings)
'strings = iamcool?end'
关于python - 正则表达式匹配字符串python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17633979/