检索在python3中,返回Non

2024-05-21 01:12:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我的正则表达式在文本文件中找不到与我正在搜索的模式匹配的。这是我的密码:

myfile = ('_%s_Mail_%s.txt' % (timestr, emailid))

urls = re.search(r'^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$', myfile)
IPs = re.search(r'^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$', myfile)
print(urls.group())
print(IPs.group())

此项不返回任何值

这个表达有什么问题?你知道吗


Tags: httpsretxt密码searchgroupmailmyfile
1条回答
网友
1楼 · 发布于 2024-05-21 01:12:06

您没有打开文件。您正在文件名上应用正则表达式。你知道吗

myfile = ('_%s_Mail_%s.txt' % (timestr, emailid))
with open(myfile, 'r') as f:
    data = f.read()
    urls = re.search(..., data)

相关问题 更多 >