Home Download Buy Blog Forum Support

Regex help

Regex help

Postby alphanimal on Tue Dec 18, 2012 11:51 am


Maybe can someone help me out with Regex...

I have a list of E-Mail recipients in the form of:
John Doe <jd@example.com>;
Jack Daniels <booze@example.net>;

I would like to use Regex to locate any invalid email addresses in that list
It doesn't have to be exact. If it matches some weird address that is actually valid (like user%1@test.domain.local) that's ok.
It's just to check

So I thought of something like this:

so this should match any character that is not likely to be seen in an e-mail-address between "<" and ">".

The problem with that is, that it matches across lines.

can I keep the regex search from wrapping around newline?

Posts: 3
Joined: Tue Dec 18, 2012 11:37 am

Re: Regex help

Postby bizoo on Tue Dec 18, 2012 12:32 pm

If you try Google with "regex email", you'll find plenty of examples.
A prefect regex that is RFC-compliant is very complicated and not very useful in practical cases because RFC support format that is probably never used.
Usually I use this one:
Code: Select all

IMHO your own regex is doomed, you should always find something existing filtering what you don't want.
Trying to find something that does not exists in regex is a nightmare.

Try using a regex editor like http://gskinner.com/RegExr/
Posts: 958
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: Regex help

Postby alphanimal on Wed Dec 19, 2012 9:36 am

OK the pattern for the e-mail address itself is good to have.
But my problem is, I want to match any invalid e-mail addresses between < and >

Is there a way in Sublime Text to find not-matching lines instead of matching lines?
Posts: 3
Joined: Tue Dec 18, 2012 11:37 am

Re: Regex help

Postby alphanimal on Thu Dec 20, 2012 9:20 am

I found negative lookahead, which seems to be useful here...

so the query would look something like:

where email is the pattern to match the mail address.

This will match any "<" before an invalid email address, so it's sufficient for me!

Would be nice if I could match the whole <...> thing, but OK as it it!
Posts: 3
Joined: Tue Dec 18, 2012 11:37 am

Return to Technical Support

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 34 guests