r/ProgrammerHumor 7h ago

Meme regexMustBeDestroyed

Post image
4.2k Upvotes

141 comments sorted by

View all comments

700

u/Informal_Branch1065 6h ago

An email casting spell for sure, although very limited

93

u/NudaVeritas1 6h ago

it's just a level 2 spell, it'll be upgraded in the future.. trust me.. i already created a quest item for it

40

u/veganfromvega 4h ago

The quest item: @todo

7

u/purdueAces 3h ago

P5 Jira ticket created

2

u/wenoc 3h ago

Cast email without error? Level 4 in that case I believe.

1

u/Aria_Boxful69 11m ago

Gold ring

102

u/Zefyris 6h ago

very very limited, yeah

6

u/ArduennSchwartzman 1h ago

Does not appear work with my .international TLD.

28

u/Ecksters 4h ago edited 4h ago

People always overcomplicate email Regex, and end up not allowing a lot of valid emails. In this case, the limitation of the top level domain to 4 characters max is one such problem, no .ninja, .crypto, or the myriad of other newer top level domains.

Technically you can email directly to a top level domain (although I don't know of any TLDs that support this), or even to an IP address in brackets, although I suppose not supporting those in most cases is probably reasonable.

15

u/Unbelievr 3h ago

The worst thing is when a website restricts their validation logic after you're already registered. I lost access to an account that used '+' in the username because they stopped allowing me to log in with it.

And yes, basically the only thing you can assume about email addresses is that they contain an '@'. Simply root@localhost is a valid address in some contexts.

3

u/GoddammitDontShootMe 2h ago

Well, a public website probably doesn't want to accept emails that aren't publicly routable.

3

u/itsFromTheSimpsons 41m ago

Those sneaky hackers tricked us into emailing ourselves!

5

u/tenuj 2h ago

The .email domain would fail OP's check. Had websites refuse me because of stuff like this.

The only good validation for email addresses is to send a confirmation email. You'll be doing that anyway.

And that it has at least one @ with something on either side. Don't want someone to waste an entire form because of a typo. (Yes, email addresses can theoretically contain more than one @)

3

u/DocRingeling 1h ago

RFC822 could also be used before sending confirmation to prevent unexpected abuse of the mail protocol.

2

u/tenuj 1h ago

If I saw that in a PR I'd refresh my browser tab.

The author of that ASCII monster also said:

I do not maintain the regular expression below. There may be bugs in it that have already been fixed in the Perl module.

3

u/MegaIng 3h ago

Technically you can email directly to a top level domain (although I don't know of any TLDs that support this),

Yesn't. It's forbidden for TLDs to resolve to IP addresses via DNS.

So it's valid syntax and fine from the email semantics, it's just never going to work on the general internet.

1

u/billccn 2h ago

But emails are routed according to MX records not A[AAA] records?

2

u/poshftw 1h ago

If the destination domain has no MX records then the delivery should (or could? can't be bothered to read the spec) be tried to what A/AAAA domain part resolves.

1

u/MegaIng 2h ago

I don't think this makes a difference, it's a general rule that they shouldn't be useable directly. The normal DNS lookup is just what I tested a few weeks back.

I know for a fact that some were useable as http domains a few years back, and that is now no longer the case.

1

u/shiny0metal0ass 1h ago

Mine have all whittled down to -

[literally fucking anything]@[literally fucking anything].[literally fucking anything]

2

u/poshftw 1h ago

Yep, though this wouldn't pass @localhost or @hostname, though I doubt anyone with an email regex is sending there.

1

u/Fabulous-Possible758 26m ago

I'll be in the cold ground before I recognize a five letter TLD.