【发布时间】:2019-10-21 20:39:53
【问题描述】:
我有一个在 regexr.com 上使用 pcre 可以正常工作的模式,但是当我将它与 python 一起使用时,它不匹配任何东西。 模式是:
.*(?<=RSA SHA256:).*(?:.*\n){3}.*
它与网站上的数据相匹配,但是当我在我的 python 脚本上运行它时却不匹配。 目标是匹配 Accepted publickey 和接下来的 3 行。 谢谢!
下面的脚本:
import re
Accepted_publickey=r'.*(?<=RSA SHA256:).*(?:.*\n){3}.*'
file=open('secure')
for items in file:
re1=re.search(Accepted_publickey,items)
if re1:
print(re1.group())
实际数据为:
Oct 21 17:27:21 localhost sshd[19772]: Accepted publickey for vagrant from 192.168.2.140 port 54614 ssh2: RSA SHA256:uDsE4ecSD9ElWQ5Q0fdMsbqEzOe0Hszilv8xhU6dT6M
Oct 21 17:27:22 localhost sshd[19772]: pam_unix(sshd:session): session opened for user vagrant by (uid=0)
Oct 21 17:27:22 localhost sshd[19772]: User child is on pid 19774
Oct 21 17:27:22 localhost sshd[19774]: Starting session: shell on pts/2 for vagrant from 192.168.2.140 port 54614 id 0
【问题讨论】:
-
你的实际行为是什么?
标签: regex python-3.x regex-lookarounds