I need to setup a regex catch-all function on postfix such that:

  • tom.(anything)@domain.com goes to tom@other.com
  • phil.(anything)@domain.com goes to phil@other.com

How can this be achieved in postfix?

3 Answers 3


Add this to your main.cf:

alias_maps = regexp:/etc/postfix/aliases

Then create /etc/postfix/aliases as follows:

/^tom\..*@domain.com$/     tom@other.com
/^phil\..*@domain.com$/    phil@other.com

See the regexp table documentation for additional information.

  • I setup as suggested. getting bounce as: (Action: failed, Status: 5.1.1, Diagnostic-Code: x-unix; user unknown). I checked postconf -m and saw regexp supported but still not working. bounce complain tom.curry@domain.com is not a real mailbox, but thats the point of alias. it should relay mail to tom@other.com which is elsewhere without complaining. (I use postfix with working mailman lists on ubuntu if that helps)
    – thevikas
    Nov 4, 2011 at 5:04
  • You may need to configure virtual aliases, etc if domain.com is a virtual alias.
    – Flimzy
    Nov 4, 2011 at 5:35
  • 3
    thanks! called it virtual_alias_maps = regexp:/etc/postfix/aliases and got it running.
    – thevikas
    Nov 4, 2011 at 6:59
  • Is it possible to use those kind of regexp in an LDAP setup?
    – Dolanor
    Feb 22, 2018 at 15:19

I'll add this for people who are wondering if it is possible to handle multiple address aliases with less configuration:

/^(.*)\..*@domain.com$/     $1@other.com

This will forward:




  • What is part_b?
    – Tigerware
    Jun 30, 2021 at 22:57

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:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.