简体   繁体   中英

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', '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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM