use*_*159 4 python regex string
i="<wx._controls.Button; proxy of <Swig Object of type 'wxButton *' at 0x2887828> >]], [[[41, 183], 'Button', <wx._controls.Button; proxy of <Swig Object of type 'wxButton *' at 0x28879d0> >]]]"
m = re.findall("<wx.(.*)> >", i)
Run Code Online (Sandbox Code Playgroud)
会给我的
["<wx._controls.Button; proxy of <Swig Object of type 'wxButton *' at 0x2887828> >]], [[[41, 183], 'Button', <wx._controls.Button; proxy of <Swig Object of type 'wxButton *' at 0x28879d0> >"]
Run Code Online (Sandbox Code Playgroud)
不过我想要它给我,
["<wx._controls.Button; proxy of <Swig Object of type 'wxButton *' at 0x2887828> >","<wx._controls.Button; proxy of <Swig Object of type 'wxButton *' at 0x28879d0> >"]
Run Code Online (Sandbox Code Playgroud)
正则表达式一直在搜索直到结束,我想把所有与正则表达式匹配的部分拿出来,有没有人知道这个的解决方案?
*默认情况下,运营商是贪婪的.你可以通过?在它之后添加一个来改变它.还记得引用字面点.
我也使组不匹配,否则你不会得到所需的输出(这似乎是你的原始代码的问题):
re.findall(r"<wx\.(?:.*?)> >", i)
Run Code Online (Sandbox Code Playgroud)
另一种可能性如下(假设恰好一个<字符出现在第一个字符之前>),这比具有惰性*运算符的版本更快:
re.findall(r"<wx\.[^<]*<[^<]*> >", i)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4348 次 |
| 最近记录: |