【发布时间】:2021-08-08 02:25:44
【问题描述】:
我正在捕获一个在文本消息中传递的字符串。该条件基于“联系人”一词。
以下是三个示例文本:
ntpd process is not running on lnx31 contact: app-support. @monitoringautomation
ntpd process is not running on lnx31 contact: app-support, @monitoringautomation
ntpd process is not running on lnx31 contact app-support @monitoringautomation
我目前的正则表达式是:
/(?i)contact:* (\S+),|(?i)contact:* (\S+)\.|(?i)contact:* (\S+)\s*/gm
我的问题是,还有其他方法可以清理或缩短这个表达式吗?我尝试了以下示例,但在使用句点或逗号时它不会捕获应用程序团队,而是将其包含在匹配中。
/((?i)contact:* (\S+)(,|\.|\s*))/gm
【问题讨论】:
标签: python regex string regex-lookarounds string-matching