Python正则表达式不起作用 [英] Python regex not working
本文介绍了Python正则表达式不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下代码:
downloadlink = re.findall("http://uploadir.com/u/(.*)\b", str(downloadhtml))
但是,当我传递以下字符串时:
However, when I pass it the following string:
<input type="text" value="http://uploadir.com/u/bb41c5b3" />
它什么也没找到,当我期待它找到:http://uploadir.com/u/bb41c5b3
.我做错了什么?
It finds nothing, when I'm expecting it to find: http://uploadir.com/u/bb41c5b3
. What am I doing wrong?
我已经使用 http://gskinner.com/RegExr/ 测试了正则表达式,它似乎是正确的.我在这里遗漏了什么吗?
I have tested the regex using http://gskinner.com/RegExr/ and it seems to be correct. Am I missing something here?
推荐答案
>>> import re
>>> html = '<input type="text" value="http://uploadir.com/u/bb41c5b3" />';
>>> regex = r'http://uploadir.com/u/([^"]+)'
>>> link = re.findall(regex, html)
>>> link
['bb41c5b3']
>>>
这篇关于Python正则表达式不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文