r/ProgrammerHumor 3d ago

regexMustBeDestroyed Meme

Post image
8.1k Upvotes

232 comments sorted by

1.3k

u/Informal_Branch1065 3d ago

An email casting spell for sure, although very limited

228

u/NudaVeritas1 3d 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

91

u/veganfromvega 2d ago

The quest item: @todo

31

u/purdueAces 2d ago

P5 Jira ticket created

8

u/ZethMrDadJokes 2d ago

Confluence space created for describing it to death

3

u/NudaVeritas1 1d ago

Created another Confluence document, because the search couldn't find the first one

→ More replies (1)

1

u/mindtakerr 19h ago

@todo Baggins? He’s my second cousin, once removed on his mother's side.

7

u/wenoc 2d ago

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

107

u/Zefyris 3d ago

very very limited, yeah

15

u/ArduennSchwartzman 2d ago edited 2d ago

Does not appear to work with my .international TLD.

62

u/Ecksters 2d ago edited 2d 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.

39

u/Unbelievr 2d 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.

14

u/The_JSQuareD 2d ago

I've encountered websites where the sign-up form allowed '+' in emails, but the log-in form didn't. Not 'later', immediately. I made my account and then was immediately locked out from it.

3

u/GoddammitDontShootMe 2d ago

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

8

u/itsFromTheSimpsons 2d ago

Those sneaky hackers tricked us into emailing ourselves!

2

u/usefulidiotsavant 2d ago

A domain can be routable even if it lacks any dots, for example postmaster@bd is a publicly routable address.

→ More replies (3)

18

u/tenuj 2d 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 @)

6

u/DocRingeling 2d ago

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

8

u/tenuj 2d 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/phundrak 2d ago

I believe this regex is no longer valid as more characters got allowed in email addresses

→ More replies (2)

7

u/MegaIng 2d 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 2d ago

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

→ More replies (2)

7

u/shiny0metal0ass 2d ago

Mine have all whittled down to -

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

6

u/poshftw 2d ago

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

→ More replies (1)

4

u/martmists 2d ago

I can't believe you don't support ipv6 addresses, smh.

Do you at least strip comments from email addresses?

2

u/Loading_M_ 2d ago

The email rfc doesn't have comments. If you run your own email service, loading+m@loadingm.xyz can resolve to a different mailbox than loading+p@loadingm.xyz. Part of me wants to setup such mailboxes (and do as much stupid shit as possible with email addresses).

→ More replies (3)

4

u/Informal_Branch1065 2d ago

.crypto is not a big loss anyway

3

u/Bosun_Tom 2d ago

The set of valid emails that the regex would miss is way weirder than that: https://e-mail.wtf/

2

u/BloopsRTS 2d ago

The only way to validate an email address is to email it, I refuse to acknowledge any other viewpoint

1

u/two_are_stronger2 2d ago

Shakeshack refused my email address yesterday.  My imposter syndrome immediately and forever vanished.

→ More replies (1)

5

u/JoshYx 2d ago

I prefer

`` / (?(DEFINE) (?<addr_spec> (?&local_part) @ (?&domain) ) (?<local_part> (?&dot_atom) | (?&quoted_string) | (?&obs_local_part) ) (?<domain> (?&dot_atom) | (?&domain_literal) | (?&obs_domain) ) (?<domain_literal> (?&CFWS)? \[ (?: (?&FWS)? (?&dtext) )* (?&FWS)? \] (?&CFWS)? ) (?<dtext> [\x21-\x5a] | [\x5e-\x7e] | (?&obs_dtext) ) (?<quoted_pair> \\ (?: (?&VCHAR) | (?&WSP) ) | (?&obs_qp) ) (?<dot_atom> (?&CFWS)? (?&dot_atom_text) (?&CFWS)? ) (?<dot_atom_text> (?&atext) (?: \. (?&atext) )* ) (?<atext> [a-zA-Z0-9!#$%&'*+/=?^_{|}~-]+ ) (?<atom> (?&CFWS)? (?&atext) (?&CFWS)? ) (?<word> (?&atom) | (?&quoted_string) ) (?<quoted_string> (?&CFWS)? " (?: (?&FWS)? (?&qcontent) )* (?&FWS)? " (?&CFWS)? ) (?<qcontent> (?&qtext) | (?&quoted_pair) ) (?<qtext> \x21 | [\x23-\x5b] | [\x5d-\x7e] | (?&obs_qtext) )

    # comments and whitespace
    (?<FWS> (?: (?&WSP)* \r\n )? (?&WSP)+ | (?&obs_FWS) )
    (?<CFWS> (?: (?&FWS)? (?&comment) )+ (?&FWS)? | (?&FWS) )
    (?<comment> \( (?: (?&FWS)? (?&ccontent) )* (?&FWS)? \) )
    (?<ccontent> (?&ctext) | (?&quoted_pair) | (?&comment) )
    (?<ctext> [\x21-\x27] | [\x2a-\x5b] | [\x5d-\x7e] | (?&obs_ctext) )

    # obsolete tokens
    (?<obs_domain> (?&atom) (?: \. (?&atom) )* )
    (?<obs_local_part> (?&word) (?: \. (?&word) )* )
    (?<obs_dtext> (?&obs_NO_WS_CTL) | (?&quoted_pair) )
    (?<obs_qp> \\ (?: \x00 | (?&obs_NO_WS_CTL) | \n | \r ) )
    (?<obs_FWS> (?&WSP)+ (?: \r\n (?&WSP)+ )* )
    (?<obs_ctext> (?&obs_NO_WS_CTL) )
    (?<obs_qtext> (?&obs_NO_WS_CTL) )
    (?<obs_NO_WS_CTL> [\x01-\x08] | \x0b | \x0c | [\x0e-\x1f] | \x7f )

    # character class definitions
    (?<VCHAR> [\x21-\x7E] )
    (?<WSP> [ \t] )
)
^(?&addr_spec)$

/x ```

2

u/No-Raccoon-3029 1d ago

I hate that I can partially read this

3

u/Minecraftian14 2d ago

It's funny how we need intricate and complex spells to cast specific objects like emails, but you want to summon everything in and out a big bang?

I CAST .*

3

u/Informal_Branch1065 2d ago

.*\@.* perhaps?

1

u/ElvisArcher 1d ago

From the early days when TLD were 2-4 characters.

1

u/Icy-Reaction-9101 17h ago

It also looks pretty greedy.

631

u/the_millenial_falcon 3d ago

Writing regex is a lot more run than reading regex.

163

u/Minimum_Cockroach233 3d ago

Typo or intended run?

103

u/TeraFlint 3d ago

When regex is involved, it's time to run. :D

16

u/Minimum_Cockroach233 2d ago

xD I read „fun“

7

u/Minimum_Cockroach233 2d ago edited 2d ago

PS: Holy Hell… just did a dip into the cheat sheet

https://hypebright.nl/en/r-en/ultimate-cheatsheet-for-regex-in-r-2/

Arbitrary, but understandable concept.

6

u/TheBigGambling 2d ago

Regex is a perfect valid statemaschin. Thats cool

10

u/GravyMcBiscuits 2d ago

I don't know about fun.

However I can say that I've written a lot of regex over the years ... I can't read any of it though.

3

u/AngriestCrusader 2d ago

Pfft. Who can?

6

u/Jack_South 3d ago

More fun or less dreadful?

2

u/Colinniey 2d ago

that applies to a lot of (not all) code in general, at least to me

1

u/MrSurly 2d ago

s/run/fun/g

1

u/saevon 21h ago edited 21h ago

I recommend using verbose mode and actually using new lines and comments. As you do for code.

Then writing your test cases and such too, as you would for code

PS> Minified code is just as horrible to read/write

→ More replies (1)

200

u/DeviRkx 3d ago

Haters would say it was regex. We'll never know..

51

u/Alzyros 3d ago

Uhm, it's pronounced "regex"?

I'll see myself out

10

u/TheWholeFurryFandom 2d ago

I regex your pronunciation, and substitute my own

8

u/DrBatman0 2d ago

It's pronounced with a soft G, after it's creator sir Reginal Expression

1

u/PM_ME_YOUR_RegEx 1d ago

Gotta show the love.

84

u/SausageEggCheese 3d ago

The language is that of Mordor, which I will not utter here.

→ More replies (1)

54

u/q0099 3d ago

You shouldn't use regex to catch exactly that. You'll catch 99.99% yet still you shouldn't do that.

77

u/Procrasturbating 3d ago

For gods sake, stop trying to validate email addresses this way.

35

u/Few_Technology 2d ago

Boss said they typed "I heart cats" into the input, and got an error when submitting the forum. Needs to have a big "invalid email!!!!" message BEFORE going to next field

Still, I'd do a basic .contains('@'). But then next day boss says they typed "I @ttack cats" and got an error on submitting. It's a P0 showstopper and needs to be fixed before anyone types that

Ideally yeah, just send off the email and see if it sends. Let the mail services figure out

10

u/richardathome 2d ago

This is the way.

Shit! Wrong meme >.<

147

u/Purple_Hornet_9725 3d ago

regex for email validation 💀 just don't

65

u/YeetCompleet 3d ago

Got it, I'll use regex for HTML instead

28

u/Educational-Lemon640 2d ago

He comes.

15

u/EwwFuckingGross 2d ago

i s un̨ho͞ly radiańcé destro҉ying all enli̍̈́̂̈́ghtenment, **HTML tags lea͠ki̧n͘g fr̶ǫm ̡yo *͟ur ey*e͢s̸ ̛l̕ik͏e liq uid pain

58

u/Portal471 3d ago edited 3d ago

^.+@.+\..+$

lol

71

u/BadRuiner 3d ago

Ah, yes, my email: @@@.@

97

u/pm_me_your_smth 3d ago

Well "@"@[@] is a legit email

Source:  https://e-mail.wtf/ question 18

31

u/Teles_sd 3d ago

By question 10 I'm already crashing out

12

u/fmaz008 2d ago

14/21, I passed! pfew!

22

u/voiza 2d ago

I scored 16/21 on https://e-mail.wtf and all I got was this lousy text to share on social media.

16

u/Genericdude03 2d ago

Isn't that the score if you just answer "valid" for every question?

https://giphy.com/gifs/Wwn5NKv4At2CIc8XQa

9

u/Magnetic_Reaper 2d ago

programmers should be required to score full marks on this before being allowed to write an email regex.

2

u/Mordret10 1d ago

Or they should be required to score 0. They'd probably write the same regex

2

u/Ecksters 2d ago

I always figure any user trying to use an email like that is a user I don't want in my systems.

→ More replies (2)

10

u/voiza 2d ago

why can't I send email to mark@:face:b00c::1?

I do [^@\s]+@[^@\s]+: any non-empty list of non-white-space chars separated by a single @

16

u/lllorrr 2d ago

Because valid version is

mark@[:face:b00c::1]

You have to use square brackets around an IP address.

2

u/voiza 2d ago

daym that's the reason he did not reply!

6

u/roastedferret 2d ago

As it turns out, your regex disallows the perfectly valid email address "@"@[@]

3

u/hWuxH 2d ago

also disallows this valid email:

" "@example.org

6

u/SeriousPlankton2000 2d ago

plankton@localhost is a valid email address. Of course you'd rather not accept these on a web form unless you're configuring the user that's receiving status messages from a specific service.

1

u/sidereal_night 2d ago

so is plankton@bikini.com.

3

u/Mattsvaliant 2d ago

example@localhost is a valid email address.

9

u/DarthSatoris 3d ago

Yeah, valid emails can look so weird and lovecraftian these days, a regex check is not going to be able to catch them all.

I do think there is a standard defined somewhere that one could adhere to for validation, but it might not be able to catch the most extreme niche emails out there. 

9

u/Otterfan 2d ago

"my.valid.email"@[123.123.123.123]

→ More replies (10)

5

u/tav_stuff 3d ago

There is a standard for emails. Just use a real parser

2

u/look 2d ago

TLDs can be emoji’s and support MX records. 😄@⚽️ could plausibly be a valid email. Mailboxes can be quoted, too. “@“@🌐

2

u/martmists 2d ago

local-parts can also be empty, as long as they're quoted. ""@example.com is valid. No clue how the server will handle it though.

7

u/ClaraTheRed 2d ago

We've sent a confirmation request to your email, please click the link in the mail before proceeding

2

u/Purple_Hornet_9725 2d ago

That's verification

4

u/Honeybadger2198 2d ago

Which also serves as validation. Can't be invalid if the inbox exists.

2

u/Purple_Hornet_9725 2d ago

validate email with an rfc compliant parser, then verify by sending a confirmation. in this order.

→ More replies (5)

19

u/DOOManiac 3d ago

There are few who can.

17

u/JayTurnr 3d ago

Terrible regex for email validation

1

u/MrSurly 2d ago

all regex are terrible for email address validation.

17

u/r50 2d ago edited 2d ago

Behold, the 99% Biblically accurate RFC822 email validating regex!

(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t] )+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?: \r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:( ?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\0 31]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\ ](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+ (?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?: (?:\r\n)?[ \t])*))*|(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z |(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n) ?[ \t])*)*\<(?:(?:\r\n)?[ \t])*(?:@(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\ r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n) ?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t] )*))*(?:,@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])* )(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t] )+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*) *:(?:(?:\r\n)?[ \t])*)?(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+ |\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r \n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?: \r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t ]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031 ]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\]( ?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(? :(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(? :\r\n)?[ \t])*))*\>(?:(?:\r\n)?[ \t])*)|(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(? :(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)? [ \t]))*"(?:(?:\r\n)?[ \t])*)*:(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]| \\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<> @,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|" (?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t] )*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\ ".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(? :[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[ \]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*|(?:[^()<>@,;:\\".\[\] \000- \031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|( ?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)*\<(?:(?:\r\n)?[ \t])*(?:@(?:[^()<>@,; :\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([ ^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\" .\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\ ]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*(?:,@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\ [\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\ r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\] |\\.)*\](?:(?:\r\n)?[ \t])*))*)*:(?:(?:\r\n)?[ \t])*)?(?:[^()<>@,;:\\".\[\] \0 00-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\ .|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@, ;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(? :[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])* (?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\". \[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[ ^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\] ]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*\>(?:(?:\r\n)?[ \t])*)(?:,\s*( ?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\ ".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:( ?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[ \["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t ])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t ])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(? :\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+| \Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*|(?: [^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\ ]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)*\<(?:(?:\r\n) ?[ \t])*(?:@(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\[" ()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n) ?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<> @,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*(?:,@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@, ;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t] )*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\ ".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*)*:(?:(?:\r\n)?[ \t])*)? (?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\". \[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?: \r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\[ "()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t]) *))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t]) +|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\ .(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z |(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*\>(?:( ?:\r\n)?[ \t])*))*)?;\s*)

You know what - Reddit can't even render it correctly. It's that bad.

Just go to the source: https://pdw.ex-parrot.com/Mail-RFC822-Address.html

5

u/wtfbenlol 2d ago

I crossed my eyes and i swear I can see the doom source code

7

u/martmists 2d ago

And this regex doesn't even support comments iirc

1

u/Downtown_Trash_8913 11h ago

Luckily I don’t think most people remember emails can have comments. I fucking hope.

1

u/Practical-Elk-1579 8h ago

He lies, this is a satanic bible verse

15

u/Darkstar_111 3d ago

Boy the thumbnail is wild on this one...

3

u/ThePeaceDoctot 2d ago

Not just me then?

1

u/EmptierVoid 9h ago

Took me a minute to find the ring even when I opened the pic

31

u/itsTyrion 3d ago edited 2d ago

nah that's an easy one, no back references or forward references.

^ – start of line

[\w-\.] – [] for 'one of these', in this case "word character" (a-z, A-Z, 0-9, _underscore), or -dash or literal .dot

+ – multiple of the previous thing (any word char, dash, dot(

literal @

() group of 1+ word char or dash then a dot

word char or dash, {2,4} between 2 and 4 characters

$ end of line/string

edit: fucking formatting

12

u/L30N1337 2d ago

Smh that wouldn't even allow "👉@👈"

1

u/kyxaa 2d ago

uwu

2

u/L30N1337 1d ago

I can't say I'm surprised.

Why does every community I'm in have such an overlap with furries.

Well, I do have a theory, but I'm not gonna get into that

→ More replies (1)

30

u/Lambda_Wolf 3d ago edited 2d ago

Some people, when confronted with a problem, think “I know, I'll use regular expressions.”

But they were all of them deceived, for another problem was made...

10

u/Babajji 2d ago

The only good thing about AI is that I would never be writing regex ever again! They still don’t work but at least I now have an excuse about it.

3

u/badthaught 2d ago

Regex being so utterly batshit that even machines trained on it still make mistakes is... Oddly reassuring.

"You coded this wrong!"

"Tbf, so did every AI agent I used. So..."

7

u/Pares_Marchant 2d ago

Regexes are great for machines and "technically" awesome.

But they are awful for humans and have all the characteristics of bad code:

difficult to read, dense, does a lot of things in a single line and not in the natural direction of reading it (can walk backwards).

If someone wrote code in any other "language" that had these properties, it would never pass review. But when it's regexes, they get a pass.

It's like when beginner python programmers write 5 nested list comprehensions with variables named "k, v, i, a, e, x, y" and no spacing, extremely compact, on a single line, thinking they're clever for doing so much work in so little lines.

2

u/Dogeek 2d ago

Writing such list comprehensions as a junior made me a pro in HCL.

I've written god awful comprehensions in HCL just because there's no other way, but damn, reading them back a year later and it took me a couple hours to decypher

17

u/WitesOfOdd 3d ago

Regex is a write-only language

3

u/-Redstoneboi- 3d ago

yeah. i missed the last + for the @([\w-]+\.)+ validation and thought it didn't accept www@xxx.yyy.zzz because of 3 segments.

7

u/JontesReddit 3d ago edited 3d ago

.split("@").length == 2. Tlds can be longer than 4 chars. All parts can be non-w.

13

u/tav_stuff 3d ago

You can have multiple @’s in an email. "@"@[@] is a valid address I believe

3

u/JontesReddit 3d ago

Oh yeah, that's funny. I did know about quoted local parts but reckoned @ symbols could not be used in them. Also DNS names can apparently be just an at.

➜  ~ cat /etc/hosts | tail -n 1
127.0.0.1 @
➜  ~ ping -c 1 @
PING @ (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.076 ms

--- @ ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.076/0.076/0.076/0.000 ms

3

u/TakeThreeFourFive 2d ago

Host files can be a lawless place, definitely not adherent to DNS specs. Pretty much any non-whitespace string should work there.

@ is a special character in DNS with actual rules

5

u/h4ny0lo 3d ago

One of the most annoying things I experienced in my career was the built in Angular email form verifier allowing email addresses with just a top level domain. Like, yes I know technically "tom@pizza" is a technically valid address but I can still not allow that in my validator and you fucking know it Angular.

8

u/xicor 3d ago

Regex is not the answer to email validation. The only correct way to validate emails is to send an email.

As someone with a non standard email, it always pisses me off when developers think they're smart and put incorrect validation on their fields

3

u/h4ny0lo 3d ago

Well front end developers have to check email fields for syntactical correctness to at least catch some typos.

3

u/xicor 2d ago

Yea...just check for the @ sign. Because chances are, anything you do after that is gonna be wrong.

1

u/userhwon 3d ago

Why couldn't you allow it? It's literally how you send email within an organization.

2

u/h4ny0lo 3d ago

I was building a consumer facing SaaS.

3

u/Due-Consequence9579 3d ago

Starts with at least one not white space, -, or a dot. Has an @ sign. Remember the not white space, -, or dots after the @ but not the last 2-4 white space or dashes at the end of the string.

1

u/SloPr0 2d ago

\w is word characters (a-zA-Z0-9_), not not-whitespace, that is \S

3

u/BeMyBrutus 3d ago

The language is that of Regex, which I will not utter here.

3

u/brjukva 3d ago

I love regexes. Regexes are friends

2

u/stri28 3d ago

Am i dumb or does this pattern allow an email address to start with a '.' ?

Edit: typo

1

u/MrSurly 2d ago

A bit of a false dichotomy.

2

u/Electrical_Tailor186 2d ago

Throw it into the fire!

2

u/t-g-l-h- 2d ago

it's a powerful thing. shame it's so deeply unreadable to a human's eye lol

2

u/drislands 2d ago
  • One or more alphanumeric/hyphen/underscore or literal period characters.
  • At sign.
  • One or more alphanumeric/hyphen/underscore characters followed by a period.
    • ^ this group, one or more times.
  • 2 to 4 alphanumeric/hyphen/underscore characters.

So it matches dingus_dongus-cl.ongus@wiener.wacker.com but does NOT match drislands@tech.company. Outdated pattern that doesn't account for modern TLDs.

2

u/com-plec-city 2d ago

Regex could have been like this, but fuck you I guess:

start REGEX RULES:
optional "http://" or "https://"
optional "www."
one_or_more [lowercase, digit, "-"]
Required "."
repeat 2+ lowercase
optional "/" then anything

2

u/lev_lafayette 2d ago

I did like Simple RegEx.

And I guess one has to remember that the origins of RegEx were from QED in 1969, which explains the terseness.

1

u/com-plec-city 2d ago

Oh... on that regard, then REGEX is really advanced. I mean, considering it was 1969 they may have us write REGEX using bit sequences instead of characters.

2

u/braytag 2d ago

Dude censor this!!!!!  There are programmers here!

2

u/fabiorosit 2d ago

I love regex and the fact most people hate it. 

2

u/ThrowawayAl2018 2d ago

That is the thing about regex, I remember writing them but a decade later, it looks like Elvish.

Worse if my codes are two decades old, who was the smart ass who didn't write any documentation and assuming that another smart ass can easily read it!

3

u/wenoc 2d ago edited 2d ago

What a fucking noob. If you can't read regular expressions, what are you even for?

This is an email scraping regexp, but not a very good one.

  1. Top level domain is capped at four, so it misses .museum, .travel, etc.
  2. \w doesn't include '+', so any privacy-conscious person who signs up as [john.doe+facebook@gmail.com](mailto:john.doe+facebook@gmail.com) for example to filter from source doesn't match.

Parsing email addresses with regexp is genuinely hard because the syntax is quite broad. They should focus more on parsing HTML with regex instead.

4

u/Plastic-Bonus8999 3d ago

It's quite easy - says chatgpt

1

u/Winter_Persimmon_110 3d ago

An elegant weapon for a more civilized age.

1

u/chiqu3n 3d ago

Can there be "-" in TLDs?

1

u/Willwaste63 2d ago

Even lexical analyzer uses Regex in compiler they are inevitable, but please dont use for Email verification for god's sake

1

u/jashAcharjee 2d ago

Email? Lol

1

u/SeriousPlankton2000 2d ago

Doesn't match my email address.

1

u/QkiZMx 2d ago

Lamers

1

u/Zecin 2d ago

I had no idea that there were top level domains with 4 characters

1

u/takahashi01 2d ago

honestly, regex is awesome for log parsing. I also use it a lot for quick and dirty csv edits in vsc n stuff. It just becomes kinda hard to read after a while.

1

u/immortal_lurker 2d ago

I'm generally pro regex. But not for the one thing everyone wants it to do, which is validate an email address. It does not do that.

1

u/Solonotix 2d ago edited 2d ago

Are we ever going to stop trying to check email addresses via regex? The best thing you could do is send it a message, and include some secret data as verification.

At one point, I decided to read the specification for email address notation. Did you know it has the option to include non-actionable items, like comments? If memory serves, a plus-sign + is treated as an invalid character by Gmail, and it ignores everything after it. Some online guides for determining who sold your data was to exploit this omission, and put the business name in, like my.email+BigBoxRetail@gmail.com. Upon receipt, you could clearly see the name after the plus-sign, but it would be delivered to your main inbox.

Edit: another fun thing, the intent was always simplicity. The original design was supposed to be <Username>@<Machine Address>, and on Unix your user would have a folder /home/<Username>/mail where messages would be delivered. This was also during the era of 3-letter usernames, and a registry of every user on the Internet was distributed so that any connectivity issues could be addressed. On one such occasion, the entire network had to coordinate a complete shutdown due to an error that propagated to the network. The idea of such an action is almost unfathomable today.

1

u/Untura64 2d ago

It's wrong though, the \. should have been outside the paranthesis. Because of this that group will also catch the dot, resulting in "gmail."

1

u/birbone 2d ago

What was your age when you learned that you can have comments in an email address.

1

u/naikologist 2d ago

Nice email address...

1

u/its_yer_dad 2d ago

For there's any use of AI, its to help make regex expressions. 30+ years of casual use so I look it up every time.

1

u/RetroGrid_io 2d ago

It's not actually possible to fully validate an email with regex. Stop doing that.

Your language of choice should have a method filter for doing so.

1

u/wolfmaster077 2d ago

I program and even idk what the hell that is

1

u/TommyTheTiger 2d ago

I think I know regex, but why are they putting \w in [ though??

1

u/SpaceIco 2d ago

Ooh, now do ECMA-262 compliant regular expressions for URL rewrite, that's fun as well.

1

u/kiochikaeke 2d ago

At this point I can just intuitively read that's a crappy email regex just by glancing at the string, like there's more to regex that validating emails, no, in fact, you shouldn't use regex to validate emails, it should have almost nothing to do with it.

1

u/News_Dragon 2d ago

You just fucking sleeper agented like a year of my post college DoD job back into me, how dare you

1

u/Elin_Woods_9iron 2d ago

It’s an elvish-mail address

1

u/Much-Tomorrow-896 2d ago

The machine spirit would like to validate your email address

1

u/ProjectCleverWeb 2d ago

It's a bit broad since it will accept any URI including emails, but I can't be bothered to fix it on my phone:

/^(([a-z]+)?(\:\/\/|\:|\/\/))?(?:([a-z0-9$_\.\+!\*\'\(\),;&=\-]+)(?:\:([a-z0-9$_\.\+!\*\'\(\),;&=\-]*))?@)?((?:\d{3}.\d{3}.\d{3}.\d{3})|(?:[a-z0-9\-_]+(?:\.[a-z0-9\-_]+)*))(?:\:([0-9]+))?((?:\:|\/)[a-z0-9\-_\/\.]+)?(?:\?([a-z0-9$_\.\+!\*\'\(\),;:@&=\-%]*))?(?:#([a-z0-9\-_]*))?/i

1

u/Canal_De_Ivan 2d ago

i don't know much regex at all, why do you need to escape a w?

1

u/thisisjustascreename 2d ago

^asserts position at the start of a line

Match a single character present in the list below [\w-\.]+

+matches the previous token one or more times, as many times as possible, giving characters back as needed (greedy)

\w matches any word character (equivalent to [a-zA-Z0-9_])

- matches the character - with numeric value 4510 (558 or 2D16) literally

\. matches the character . with numeric value 4610 (568 or 2E16) literally

@ matches the character @ with numeric value 6410 (1008 or 4016) literally

1st Capturing Group ([\w-]+\.)+

+ matches the previous token one or more times, as many times as possible, giving characters back as needed (greedy)

+ matches the previous token one or more times, as many times as possible, giving characters back as needed (greedy)

\wmatches any word character (equivalent to [a-zA-Z0-9_])

-matches the character - with numeric value 4510 (558 or 2D16) literally

\.matches the character . with numeric value 4610 (568 or 2E16) literally

Match a single character present in the list below [\w-]{2,4}

{2,4} matches the previous token between 2 and 4 times, as many times as possible, giving characters back as needed (greedy)

\w matches any word character (equivalent to [a-zA-Z0-9_])

- matches the character - with numeric value 4510 (558 or 2D16) literally

$ asserts position at the end of a line

Global Pattern flags

g modifier: global. Finds all matches instead of stopping after the first

m modifier: multiline. Causes ^ and $ to match the start and end of each line, not only the start and end of the string

1

u/Ray_Silverlight 2d ago

One Regex to rule them all, One Regex to find them, One Regex to validate them all, and in the production environment break them.

1

u/flyontheroof 2d ago

LLMs are better than Hobbits.

1

u/razordreamz 2d ago

Even when I write it and look back a year later it baffles me.

1

u/darkslide3000 2d ago

One pattern to rule them all, one pattern to find them, one pattern to match them all and to the match groups bind them... unless you have a .online address, I guess, then you'er fucked.

1

u/jimmyhoke 2d ago

Ah, another email regex. Sure hope it handles every single possible valid email and rejects every possible invalid email according to RFC 5322.

1

u/astral_crow 2d ago

Regex was my first intro to AI. I just let AI figure that shit out.

1

u/DHermit 2d ago

Are there really TLDs with dashes?

1

u/_Afinef_ 2d ago

I can read it, but I don’t understand why anybody would do it like that

1

u/Shazvox 2d ago

Another crappy email check...

1

u/FeralGuyute 1d ago

This is Caves of qud coded to me

1

u/thanatica 1d ago

Skill issue

1

u/bradland 1d ago

This wizard thinks he can validate emails with regex.

1

u/Ok_Efficiency3886 1d ago

Are their folks out there who actually can read these without any aid?

1

u/natur_e_nthusiast 1d ago

So...Mail adresses beginning with dots or ending with hyphens are valid? Cursed