5 ms·
The Email::Valid Perl distribution ships with a more than 6000 character regex to validate E-Mail addresses. Both goo.gl and bit.ly refused to shorten it, and
by avar 9y ago
The Email::Valid Perl distribution ships with a more than 6000 character regex to validate E-Mail addresses.
Both goo.gl and bit.ly refused to shorten it, and when I tried to paste the link here HN refused to accept my comment.
But on a machine with Email::Valid installed do:
perl -MEmail::Valid -wE 'say $Email::Valid::RFC822PAT'
And copy the output into the Regexper form. It takes a while to render, but it'll eventually complete.
- gruez 9y ago>Both goo.gl and bit.ly refused to shorten it, and when I tried to paste the link here HN refused to accept my comment. github gist?
- shakna 9y agoTry this: https://gist.github.com/shakna-israel/83b84cd8465d131f9686906d15fe60d5 https://gist.github.com/shakna-israel/83b84cd8465d131f968690...
- shakna 9y agoWow. Despite the utterly insane complexity of a regex of that size, it doesn't seem to do an insane amount of branching. Maximum depth of choices seems to be about 4, which is less than a lot of other regex examples I've seen here. That being said... That regex is just noise. Nobody can tackle it all at once or by themselves, unless they specialise in just regex. It's 6599 characters, at least on my system. So at a wild stab, its the equivalent of 4,500 lines of obfuscated code. You can't audit it, you just kinda have to trust it, and hope. But with something like regexper, I can at least read it.
- avar 9y agoI can't remember where, but there's some version of that regex somewhere that uses variables for interpolation in subsequent regexes. Viewed like that it's really not that complex, most of it is repetition of previously used regex sequences, it's only when fully expanded that it becomes so humongous.
- shakna 9y agoThe pattern is Jeffrey Friedl's, from his book Mastering Regular Expressions. And as clear as the source could be made, I feel the fact that so many people have just copied and pasted it means that any understanding is lost, and they're just praying and hoping, because a regex of that size is actually difficult for them to comprehend.
- singingfish 9y agoHere, have a 1800 line regex which parses perl: https://metacpan.org/source/DCONWAY/PPR-0.000003/lib/PPR.pm#L20 https://metacpan.org/source/DCONWAY/PPR-0.000003/lib/PPR.pm#...
- joosters 9y agoThis short link seems to work: http://1b.yt/exfqj http://1b.yt/exfqj (regexper.com doesn't seem to cache results, so this is going to hit their site hard...) [edit: oops, it's all client-side so no problem for the site]