Skip to main content
 首页 » 编程设计

python之生成额外输出的正则表达式

2025年05月04日22bhlsheji

我有一个这样的字符串:

st = "url=these,url=are,url=test,url=questions" 

现在我需要根据这个字符串生成所有 url 的值。现在我使用的正则表达式是这样的:

import re 
re.findall(r'([^\(url=\)]+)',st) 

现在我想要的输出是 ['these,', 'are,', 'test,', 'questions'] 但是我的正则表达式给出了 ['these,', 'a', 'e,', 'test,', 'q', 'estions'] 这作为输出。

那么,我修改后的正则表达式应该是什么,以及为什么我的正则表达式没有给我想要的输出。

请您参考如下方法:

你可能想要类似下一个的东西:

>>> re.findall(r'url=(\w+)',st) 
['these', 'are', 'test', 'questions']