python - 正则表达式匹配字符串python

标签 python regex

我想匹配以下字符串:

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/

相关文章:

python - 如何在python中构建动态sql查询并使用executemany()插入?

python - 将文本添加到现有邮件正文中

python - 副窗无槽

带有索引/偏移量的 Ruby gsub?

php - 预匹配 :/usersname or/username/foo

python - 从单选按钮获取输入

python - pandas dataframe resample 聚合函数使用具有自定义函数的多列?

javascript正则表达式在字符串中查找图像url

从文本中删除标点符号(符号 & 除外)

regex - 匹配俄语的正则表达式,允许 .htaccess 中的所有西里尔字符