I'm trying to create a regex for my Postfix header_checks file so it will match a string that does not include .com, .net or .org domain extension.
The following regex appears to work in regex101, but fails in Postfix.
/^From: .*\.(?!(com|net|org)>)/ HOLD
All mail (including .com, .net, etc) get held in queue, and that's obviously not what I want.
I want the regex to match on strings like :
From: Example Mail <example@domain.bid>
From: Example Mail <example@domain.bid.co>
Any ideas where I am going wrong with my regex?
According to regexp_table the regular expression is matched with multi-line
mode off, which implies that ^
only matches the start of the string and not
the start of the line.
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.
(By the way, I prefer "[.]"
over "\."
and would use a non capturing group for the alternatives: "(?:com|net|org)"
).