Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想匹配以下字符串:
strings = iamcool.iplay=ball?end
我想删除开始(包括“。”)和直到“?”的项目,所以我想删除.iplay=ball,所以我应该有iamcool?end
.iplay=ball
iamcool?end
这是我的正则表达式:
print re.sub(r'\.\.*?','', strings)
我不确定如何在“?”处停下来。
使用[^?]匹配除?.
[^?]
?
>>> re.sub(r'\.[^?]*', '', strings) 'strings = iamcool?end'