我正在尝试为我的Postfix header_checks文件创建一个正则表达式,因此它将匹配不包含.com,.net或.org域扩展名的字符串。
以下正则表达式似乎在regex101中有效,但在Postfix中失败。
/^From: .*\.(?!(com|net|org)>)/ HOLD
所有邮件(包括.com,.net等)都被排在队列中,这显然不是我想要的。
我希望正则表达式匹配字符串,如:
From: Example Mail <example@domain.bid>
From: Example Mail <example@domain.bid.co>
我的正则表达式出错的任何想法?
答案 0 :(得分:1)
根据regexp_table,正则表达式与多行匹配
mode off,表示^
仅匹配字符串的开头而不匹配
这条线的起点。
By default, matching is case-insensitive, and newlines are not treated as special characters. The behavior is controlled by flags, which are toggled by appending one or more of the following characters after the pattern: i (default: on) Toggles the case sensitivity flag. By default, matching is case insensitive. m (default: off) Toggle the multi-line mode flag. When this flag is on, the ^ and $ metacharacters match immediately after and immediately before a newline character, respectively, in addition to matching at the start and end of the input string.
(顺便说一下,我更喜欢"[.]"
而不是"\."
,并且会使用非捕获组替代:"(?:com|net|org)"
)。