I need to setup a regex catch-all function on postfix such that:
- tom.(anything)@domain.com goes to firstname.lastname@example.org
- phil.(anything)@domain.com goes to email@example.com
How can this be achieved in postfix?
Add this to your main.cf:
alias_maps = regexp:/etc/postfix/aliases
/etc/postfix/aliases as follows:
/^tom\..*@domain.com$/ firstname.lastname@example.org /^phil\..*@domain.com$/ email@example.com
See the regexp table documentation for additional information.
I don't know Postfix, but the regex you're looking for is:
Then you substitute the first matching group with nothing (empty string), and the second group with "other".
As an example, in Perl you would do:
my $regex = '^.*(\..*)@(domain).com$'; $your_string =~ /$regex/; $aux = $2; $your_string =~ s/$1//; $your_string =~ s/$aux/other/; print $your_string;
Of course this works only if email address has "domain" as domain. If you want domain to be anything, then the regex would be: