如果在编译中提取多个值,我想在Python3中帮助re
。
值:
[+] Name: Responsy-v4-0-3 - v4.0.3
[+] Name: add-to-any - v1.5.8
[+] Name: captcha - v4.1.3
[+] Name: wordpress-popular-posts - v3.2.3 `
我尝试了以下内容:
re.compile('Name: (. *) -')
它返回"Responsy-v4-0-3"
,我怎么能得到其余的?
答案 0 :(得分:0)
您需要逐行迭代,然后在每一行上应用正则表达式。或者只需在re.findall
函数中使用上述正则表达式。
示例:强>
>>> s = '''[+] Name: Responsy-v4-0-3 - v4.0.3
[+] Name: add-to-any - v1.5.8
[+] Name: captcha - v4.1.3
[+] Name: wordpress-popular-posts - v3.2.3'''
>>> re.findall(r'Name: (.*) -', s)
['Responsy-v4-0-3', 'add-to-any', 'captcha', 'wordpress-popular-posts']