Home Download Buy Blog Forum Support

Regex help

Regex help

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

Hi!

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:
<.*[^0-9a-z\-\._@].*>

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?

Thanks!
Daniel
alphanimal
 
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
[a-zA-Z0-9.!#$%&'*+-/=?\^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*

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/
bizoo
 
Posts: 886
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?
alphanimal
 
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...
http://www.regular-expressions.info/lookaround.html

so the query would look something like:
<(?!email)

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!
alphanimal
 
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 22 guests