Python 正则表达式,如何在正则表达式中对项目进行分组
我在创建正则表达式时遇到问题。 以下是正则表达式应起作用的文本示例:
<b>Additional Equipment Items</b> <br>
40001 <br>
1 Battery Marathon L (8 cells type L6V110) <br>
40002 <br>
我现在要选择的是 >>1<< >>Battery Marathon L(8 节电池类型 L6V110)>>。
因此,我生成了以下正则表达式:
found = re.findall('<b>.*Items\s*<\/b>\s*<br>(?:\s*[1-4]0[0-9][0-9][0-9] <br>\s*(\d*) (.*) <br>)*', content)
似乎外部正则表达式确实匹配,但内部组是空的:(
有什么建议吗?!
I'm having trouble creating a regex.
Here is a sample of the text on which the regex should work:
<b>Additional Equipment Items</b> <br>
40001 <br>
1 Battery Marathon L (8 cells type L6V110) <br>
40002 <br>
What I now want to select is >>1<< and >>Battery Marathon L (8 cells type L6V110)<<.
Therefore I have produced the following Regex:
found = re.findall('<b>.*Items\s*<\/b>\s*<br>(?:\s*[1-4]0[0-9][0-9][0-9] <br>\s*(\d*) (.*) <br>)*', content)
Seems like the outer regex does match, but the inner groups are empty :(
Any suggestions?!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我有时只是讨厌正则表达式。一些空格属于我......
这是解决方案:
Okay I sometimes just hate Regex. Some whitespaces owned me...
Here is the solution: