Regex for VERP header

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Can any one suggest me the REGEX that will work for all the VERP
headers....the VERP header format is something like this:




If the return path is something and the recipient email is , the verp address should be


The REGEX should be able to parse any VERP header....
Thanks much...

Opesh Alkara

Re: Regex for VERP header

Quoted text here. Click to load it


ThinFlash: Linux thin-client on USB key (flash) drive
BashDiff: Super Bash shell /

Re: Regex for VERP header


I got some help from Carl Reynolds of

here is the conversation:


Opesh wrote:

Quoted text here. Click to load it
I looked at the sendmail-hacks.txt for about five minutes. I don't want

to try to figure out what it's saying. It seems to start in the middle
of a conversation I did not hear the beginning of.

As far as creating a regular expression to handle the strings you want,

I know enough about regular expressions to try to advise you to create
your own.

Note that I have delimited all the regular expressions with slant-signs

(/). If your syntax doesn't require the expressions to be delimited,
copy the examples I have given without the slant-signs.

You are asking to create a regular expression to handle a string of the

Assuming there are no hyphens (-) in the 'something' part of  of the
string let's start the pattern with

This says: match from the start of the string. Find anything that is
a hyphen one or more times. Followed by a hyphen. The "anything that is

not a hyphen" part gets put into a group to be used later. This will be

called group $1

Next we match the 'mynameisxyz' part of the string with

This is similar to the first pattern. It says Match anything that is
an equal sign one or more times and put that into a group called $2.
Then match the equal sign.

As far as matching the e-mail address, if you are trying to match any
e-mail address, it needs to conform to RFC 822
< - <quote>which is filled with
impenetrable discussions on "sequences of lexical symbols" such as
"atoms", "special characters", "domain-literals" and
Over the last couple of weeks I have read a number of articles on
matching e-mail addresses with regular expressions and they all agree
that there is no way to match all the addresses specified by RFC 822
with a single regular expression.

However, if you can restrict the addresses you want to match to a known

subset of RFC 822, there is hope you can match all of that subset.

Here is an expression that seems to match a very large subset of e-mail

addresses. It comes from .

He claims to match every possible e-mail address, but that claim is not


Now we have three expressions to match the individual parts of your
string. Let's put them together to create one monster expression to
parse the entire line

You will need to test this line against the e-mails you want to pass
through your VERP filter and see if it will do what you want.

You said you are willing to restrict the e-mail addresses to the form

In that case use

However, keep in mind that this is a very small subset of the valid
e-mail addresses allowed on the net.

This gives you a place to start figuring out what does and what doesn't



Re: Regex for VERP header

Opesh wrote:
Quoted text here. Click to load it

If you're trying to create milters (sendmail filters), your best
bet is to get mimedefang and spamassassin... no point in reinventing
the wheel. / / /

Quoted text here. Click to load it


Re: Regex for VERP header

Opesh wrote:

Quoted text here. Click to load it

The Perl Mail::RFC822::Address claims to be able to parse RFC 822 addresses,
and if you read the specs I believe it is true (hint: look at how the regexp
is being built in the Perl source, and refer to RFC 2822).

The monstrous regexp can be seen at



Klaus Alexander Seistrup

Site Timeline