开发者

Python RegEx Discrepancy vs Kodos and RegExr: Can't Filter Specific Character in Python

I'm using Python 2.6.3. When I do:

import re, urllib
f = urllib.urlopen(website)
z = f.read()
a = re.findall(r'(\b\d*\SLegos\b)[^\\/bLegos\b]', z)
print a

I get:

['/Legos', '/Legos', '525Legos', '53Legos', '11Legos', '8Legos', '10Legos', '2Legos', '0Legos', '0Legos', '0Legos', '0Legos', '9Legos', '1Legos', '0Legos', '0Legos', '0Legos', '/Legos']

If I put the website as source code into either Kodos or RegExr by gSkinner and use my above RegEx code they both say I should get:

'525Legos', '53Legos', '11Legos', '8Legos', '10Legos', '2Legos', '0Legos', '0Legos', '0Legos', '0Legos', '9Legos', 开发者_StackOverflow中文版'1Legos', '0Legos', '0Legos', '0Legos'

Which is much closer to the data I want.

How do I drop the '/Legos' from returning in my Python regex?

Thanks,

Adrian


your regex is too complicated and erroneous, you could just use:

\b(\d+Legos)\b

if you don't really need Legos in your output, you could of course simply move it out of the brackets:

\b(\d+)Legos\b
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜