如何将正则表达式从 PCRE 转换为 POSIX 格式,以警告重复运算符操作数无效?
尝试对来自经过身份验证的 postfix 用户的中继消息的收到标头进行匿名化,有一个来自 https://we 的示例.riseup.net/debian/anonymizing-postfix:
/^Received: from (.* \([-._[:alnum:]]+ \[[.[:digit:]]{7,15}\]\)).*?([[:space:]]+).*\(Authenticated sender: ([^)]+)\).*by (auk\.riseup\.net) \(([^)]+)\) with (E?SMTPS?A?) id ([A-F[:digit:]]+).*/ REPLACE Received: from [127.0.0.1] (localhost [127.0.0.1])$2(Authenticated sender: $3)${2}with $6 id $7
编辑文件 regexp:/etc/postfix/header_checks
时,结果是一条错误消息:
第 15 行: 重复操作符操作数无效
现在我的猜测是上面的正则表达式是 PCRE 格式,我的 Postfix 请求 POSIX 兼容的正则表达式。
如何使上述正则表达式 POSIX regexp 兼容,以便在 Postfix header_checks 文件中使用?
Trying to anonymize received headers for relayed messages from authenticated postfix users, there is an example from https://we.riseup.net/debian/anonymizing-postfix:
/^Received: from (.* \([-._[:alnum:]]+ \[[.[:digit:]]{7,15}\]\)).*?([[:space:]]+).*\(Authenticated sender: ([^)]+)\).*by (auk\.riseup\.net) \(([^)]+)\) with (E?SMTPS?A?) id ([A-F[:digit:]]+).*/ REPLACE Received: from [127.0.0.1] (localhost [127.0.0.1])$2(Authenticated sender: $3)${2}with $6 id $7
When editing the file regexp:/etc/postfix/header_checks
the result is an error message:
line 15: repetition-operator operand invalid
Now my guess is that the above regex is in PCRE format, where my Postfix requests a POSIX compatible regular expression.
How to make the above regular expression POSIX regexp compliant for use in a Postfix header_checks file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的预感是正确的,
.*?
是 PCRE 构造:.*
是正常的“任何字符,尽可能多次,至少零次”,并且尾随问号将其更改为“...尽可能少的次数...”。 SUSv4 说:我没有过多研究该模式,但您应该能够解决这种特定的不兼容性:下一个子模式是
([[:space:]]+)
,因此您应该能够将其重新表述为“任何非空格字符...”:或者可以通过省略问号来解决问题。毕竟,太空吞噬者后面跟着另一个
.*
。Your hunch is correct,
.*?
is a PCRE construct:.*
is normal "any character, as many times as possible, at least zero times", and the trailing question mark changes that to "... as few times as possible ...". SUSv4 says:i haven't studied the pattern too much, but you should be able to work around this particular incompatibility: the next subpattern is
([[:space:]]+)
, so you should be able to reformulate it as "any non-space character...":or maybe just get rid of the problem by omitting the question mark. the space-eater is followed by another
.*
after all.