Regex 101
regex101.com
regex101.com
use re 'Debug';
or even better use re 'debugcolor';
and watch the state machine matching.Very useful for debugging.
http://perldoc.perl.org/re.html#%27Debug%27-mode
Another great resource is:
http://search.cpan.org/dist/Regexp-Debugger/lib/Regexp/Debug...
I do feel like these subtle differences are the main cause of bugs in programs containing regexes; compounded by the fact they aren't super-readable, especially for people who don't use them frequently.
Tools like this are IMO really valuable for code reviews and it's nice to see that this one does have a flavour switch on the LHS with some of the main implementations.
... I should probably come up with some mappings so the \v is inserted automatically.
The best / easiest way that I've taught regex is to pop open a text editor and start searching for stuff. Start by searching for some letters, then a string with spaces, then a line break. From there I point people towards stuff like Apache config file conditionals / URL re-writes etc.
I thought I knew regexps, then I read "Mastering regular expressions". After that I was embarrassed. :-)
All history aside, 1: Sed&awk 2: Mastering Regexp 3: The vim book has a great chapter on regular expressions (it's been ~10 years since I've touched it, but I remember being gifted a copy from a colleague of my father when I was in my teens and it helped me grok it)
The glibc programming manual is actually really comprehensive. kernel.org/docs/man-pages/ gives a pretty in depth analysis of POSIX.2 regex. I'm sure Perldocs also have PCRE's very well documented.
Validating emails with regexes is one of those things that seems like it should be fairly straightforward, but thanks to the language in the RFC it is actually a nightmare of rabbit holes filled with landmines.
http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html
I don't know about unicode, but I do note it says it doesn't handle comments (because, apparently, they can be nested - and perl's REs lack recursion).
(rest of the page is filled with line noise)
LOL
Really. Email addresses should have never been allowed to have comments.
Since every new RFC maintains compatibility with this one, we'll probably be stuck with these poor choices for decades.
I guess this is what you're referring to: James Doe <jdoe@a.com>
The email - which is inside the <> - should be parsed correctly, while the rest should be treated as a "comment" [1].
Stuff like:
* comments are allowed with parentheses at either end of the local-part; e.g. john.smith(comment)@example.com and (comment)john.smith@example.com are both equivalent to john.smith@example.com. [1]
* Also have a look at quotes
At first I thought you were a bot. Then that your English was not very good.
Looking at your history clearly both are false.
What did you mean?
Thank you!
* "Abc\@def"@example.com
* "Fred Bloggs"@example.com
* "Joe\\Blow"@example.com
* "Abc@def"@example.com
* customer/department=shipping@example.com
* $A12345@example.com
* !def!xyz%abc@example.com
* _somename@example.com
http://haacked.com/archive/2007/08/21/i-knew-how-to-validate...Have further RFCs not deprecated most of the braindamage from 822? If not, why? Are there really people who are still trying to use such horrible abominations for their email address?
Anything else is going to give you a false negative sooner or later. Yeah, you can spend hours framing a complicated expression that carefully tests for exactly what the current bucket of RFCs specify, but you're guaranteed to run into an MTA somewhere that disagrees with you, and you can argue until the cows come home that you're right and they're wrong, but it's still you that's going to have to change to accommodate them in the end.
^(?("")(""[^""]+?""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9]{2,17}))$
This and other email validation here: https://github.com/neosmart/web/blob/master/Web%20Toolkit/Em...In any case, it probably won't be too long before we get emoji TLDs, or UTF8 flags to replace the country-code :-D
The only regret I have is that many of the interesting regexes we see in the course of our work are not something which we can type into someone else's web site. Fortunately there are others who have looked at the idea of making an off-line version:
Regex is weird anyway but it's often a surprise just some weird string that's close to what you thought you wanted comes up.