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.
我想在 python 中执行正则表达式搜索操作以匹配所有内容,但只有一个字符(在此示例中位于末尾):
expression = re.compile(r'http:\/\/.*')
上面的正则表达式将匹配整个 url:http://stackoverflow.com/questions/ask;而我想要做的是得到一个没有最终;字符的匹配。
http://stackoverflow.com/questions/ask;
;
您可以使用否定字符类而不是dot (.)最后:-
dot (.)
expression = re.compile(r'http:\/\/[^;]*')