【发布时间】:2022-11-16 04:48:32
【问题描述】:
非常简单的正则表达式,我正在尝试从日志中提取 IP。但是 group(1) 是空的,这是给定的。有没有更好的方法来解决这个问题?
sourceip_regex_extract = re.compile(r"{}".format(sourceip_syslog_regex))
sourceip_extract = sourceip_regex_extract.search(message)
sourceip_txt = sourceip_extract.group(1)
Regex101:https://regex101.com/r/jmtQci/1
【问题讨论】:
-
参见regex101.com/r/jmtQci/2、
\b(?:from |inside:)(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) -
你能分解这个吗?加上 regex101 说“您的正则表达式与主题字符串不匹配。”
-
我添加了
\b,删除它