加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则表达式,首先找到 – Python

发布时间:2020-12-14 05:55:39 所属栏目:百科 来源:网络整理
导读: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) 会给我的 ["wx._controls.Butt
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)

会给我的

["<wx._controls.Button; proxy of <Swig Object of type 'wxButton *' at 0x2887828> >]],<wx._controls.Button; proxy of <Swig Object of type 'wxButton *' at 0x28879d0> >"]

不过我想要它给我,

["<wx._controls.Button; proxy of <Swig Object of type 'wxButton *' at 0x2887828> >","<wx._controls.Button; proxy of <Swig Object of type 'wxButton *' at 0x28879d0> >"]

正则表达式一直在搜索直到结束,我想把所有与正则表达式匹配的部分拿出来,有没有人知道这个的解决方案?

解决方法

*运算符默认是贪心的.你可以通过添加一个来改变它吗?在它之后.还记得引用字面点.

我也使组不匹配,否则你不会得到所需的输出(这似乎是你的原始代码的问题):

re.findall(r"<wx.(?:.*?)> >",i)

另一种可能性如下(假设一个<字符在第一个>之前出现),这比具有lazy *运算符的版本更快:

re.findall(r"<wx.[^<]*<[^<]*> >",i)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读