python - 正则表达式在在线正则表达式解释器中匹配,但在python中不匹配

标签 python regex

我正在尝试从页面源中找到一个正则表达式模式,它在正则表达式在线编辑器中很好用,但是当我在笔记本中尝试时,找不到任何匹配项

here is my regex

http://www.yifysubtitles.com/subtitle/.+zip


它可以在在线编辑器中正常工作:

image

但不是jupyter笔记本:

image

我所缺少的,请帮忙。



文字,以供参考:

...    
[DOWNLOAD SUBTITLE](http://www.yifysubtitles.com/subtitle/blockers2018web-
dlx264-fgt-english-128543.zip)
...

最佳答案

您的搜索字符串跨越多行。要跨行匹配(在python中,默认情况下不会完成此操作),请在re.DOTALL调用中添加re.search标志:

>>> p = r'http://www\.yifysubtitles\.com/subtitle/[^.]+\.zip'  # improved, ty @dawg
>>> re.search(p, text, flags=re.DOTALL)
<_sre.SRE_Match object; span=(481, 565), match='http://www.yifysubtitles.com/subtitle/blockers201>


另外,不要忘记转义文字.字符,如果不进行转义,则不会将它们视为相同(.如果不进行转义,将与任何字符匹配。

关于python - 正则表达式在在线正则表达式解释器中匹配,但在python中不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51006927/

相关文章:

python - 在 python 中使用正则表达式返回唯一匹配项

python - 将两个时间表与一些省略的数据合并

python - Django-admin动态过滤ForeignKey字段

python - py2exe的优点/缺点是什么

python - Scrapy:使用正则表达式跟踪链接

javascript - 为什么这个 javascript 验证总是失败

javascript - 点 ?正则表达式字符串中的字 rune 字

python - 在 Python 中,如何在保持原始调用堆栈的同时检查并重新引发异常?

python - 日期时间选择器 : how to set the min/max date based on SQL database

regex - Notepad++ : Insert blank new line after match of some string