Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
正则表达式匹配字符串python_Python_Regex - Fatal编程技术网

正则表达式匹配字符串python

正则表达式匹配字符串python,python,regex,Python,Regex,我想匹配以下字符串: strings = iamcool.iplay=ball?end 我想删除从“.”开始一直到“?”的项目,所以我想删除.iplay=ball,所以我应该有iamcool?end 这是我的正则表达式: print re.sub(r'\.\.*?','', strings) 我不知道如何停止在“?”使用否定字符类[^?],该类匹配除?之外的任何内容 >>> re.sub(r'\.[^?]*', '', strings) 'strings = iamcool

我想匹配以下字符串:

strings = iamcool.iplay=ball?end
我想删除从“.”开始一直到“?”的项目,所以我想删除
.iplay=ball
,所以我应该有
iamcool?end

这是我的正则表达式:

print re.sub(r'\.\.*?','', strings)

我不知道如何停止在“?”

使用否定字符类
[^?]
,该类匹配除
之外的任何内容

>>> re.sub(r'\.[^?]*', '', strings)
'strings = iamcool?end'