[英]Python RegEx Discrepancy vs Kodos and RegExr: Can't Filter Specific Character in Python
I'm using Python 2.6.3. 我正在使用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: 如果我通过gSkinner将网站作为源代码放入Kodos或RegExr中,并使用上面的RegEx代码,他们俩都说我应该得到:
'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? 如何在返回的Python正则表达式中删除
'/Legos'
?
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: 如果您的输出中确实不需要
Legos
,则当然可以将其移出括号:
\b(\d+)Legos\b
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.