Sublime Forum

Regex help

#1

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

0 Likes

#2

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:

[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/

0 Likes

#3

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?

0 Likes

#4

I found negative lookahead, which seems to be useful here…
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!

0 Likes