开发者

Python regex, how-to group an item within a regex

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 :(

开发者_StackOverflow中文版

Any suggestions?!


Okay I sometimes just hate Regex. Some whitespaces owned me...

Here is the solution:

<b>.*Items\s*<\/b>\s*<br>(?:\s*[1-4]0[0-9][0-9][0-9] <br>\s*(\d*)\s*(.*) <br>)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜