Take the 2-minute tour ×

I am trying to match a list of colon separated emails. For the sake of keeping things simple, I am going to leave the email expression out of the mix and match it with any number of characters with no spaces in between them.

The following will be matched...

somevalues  ;somevalues;       somevalues;


somevalues; somevalues             ;somevalues

The ending ; shouldn't be necessary.

The following would not be matched.

somevalues ;   some values    somevalues;


some values; somevalues some values

I have gotten this so far, but it doesn't work. Since I allow spaces between the colons, the expression doesn't know if the space is in the word, or between the colon.


The following is matched (which shouldn't e)

somevalue ; somevalues  some values;

How do I make the expression only allow spaces if there is a ; to the left or right of it?

share|improve this question
([a-zA-Z]*\s*\;?\s*)* would consider only the first colon if i am not mistaken hence why it matchs the second one aswell. –  Prix Jul 4 '10 at 18:51
here you can know everything you need about regex <strong> click here </strong> –  Saher Jul 4 '10 at 20:38
add comment

4 Answers

up vote 1 down vote accepted

This following PCRE Expression should work.


However if putting the email address validation regular expression on this will require replacing \w+ with (?:<your email validation regex>)

Probabbly This is exactly what you want, tested on http://regexr.com?2rnce

EDIT: However depending on the language you might? need to escape ; as \;

share|improve this answer
This is exactly what I am looking for. I am using the String.Split in c# but I wanted to validate the textbox on client side before I do anything for performance reasons. –  Paul Knopf Jul 4 '10 at 20:11
Can you post the final regex with email address validation ?? –  Neel Basu Jul 5 '10 at 4:42
add comment

Why not just split on semi colon and then regex out the email addresses?

share|improve this answer
If I'm not mistaken a semicolon is a valid character in RFC822 email addresses so you should be careful when using this that the emails are guaranteed not to contain any semicolons. –  Mark Byers Jul 4 '10 at 18:57
interesting - wonder how my outlook handles that. I think RFC2822 has superceded but I haven't read that one either. –  matt-dot-net Jul 4 '10 at 19:07
add comment

The problem comes from the ? in \;?


should work.

share|improve this answer
add comment



Note that I changed * to + on the e-mail pattern since I assume you don't want strings like ; to match.

share|improve this answer
add comment

Your Answer


