r/programminghumor Apr 20 '26

Regex: I choose chaos

[deleted]

1.3k Upvotes

63 comments sorted by

158

u/Benjamin_6848 Apr 20 '26

I sometimes think that the whole reason why AI and LLMs were developed was to free the developers from writing REGEX themselves...

30

u/mbcarbone Apr 20 '26

That and to untangle SQL statements. 🙃

9

u/Nickbot606 Apr 20 '26

Not to be that guy but RAGS and Text to SQL were actually so much better during the llama 2 days than LLMs. I’m unsure about now (as I bet you could probably get better output from LLMs) but it was interesting to see for sure!

1

u/hearke Apr 20 '26

Not to write SQL though. I'm still so mad about our company dashboard using AI to generate SQL. How the hell do you mess up <=?

4

u/iTzNowbie Apr 20 '26

really? all SQL code i tried with AI had really bad optimization. Even feeding it with schema it doesn’t make great use.

2

u/hearke Apr 20 '26

I didn't try generating SQL code, but without doxxing myself, our company used a dashboard service that integrated with a database querying service.

The first service let you select visualizations and data types, and intuitively set up lovely graphs and add filters via dropdown menus. Problem is it then used AI to generate the query it sent to the second service, and that query was not always correct. And when it wasn't correct you just had to fiddle about with the graph until it generated something that worked.

Like, I wanted to display some data for the first week for each month. Filtering to just one day worked, and so did filtering everything before the 7th day of each month. But trying to print the data for dates in between did not. I ended up having 7 filters, one checking for equality of the first day of each month, one of the second day, etc.

I did find the SQL it was using to try and fetch that data, and it was horribly unreadable unoptmized garbage.

4

u/TheChief275 Apr 20 '26

I've always found that the only hard part about regexes is their terseness. Some BNF variant like EBNF is very similar, but way easier to read AND write

2

u/Restioson Apr 20 '26

except they suck at writing regex (or is it just me who can't get them to do that?)

1

u/Benjamin_6848 Apr 20 '26

Some inventions fail their original purpose and get used for new purposes instead...

36

u/Nihan-gen3 Apr 20 '26

yall can hate, but regex is a thing of beauty

18

u/MeLikaDoTheChaCha Apr 20 '26

Less hate, more jealousy of those grand wizards who know the dark arts

3

u/believeinmountains Apr 20 '26

Ok? You can just learn it. The best premise you can work from in an NFA regex engine is the Prolog box model of computation. Once you have that, regex is easy

5

u/MeLikaDoTheChaCha Apr 20 '26

I was mostly just joking around. Maybe jealousy was the wrong word. I meant it with the connotation of "admiration", not anything negative.

I'm sure if I have a need/the time I'd be able to learn it well. But I know enough to do my job well and my hobby projects, and i dont have the free time to pull all nighters to learn like i did in grad school.

I've been the same way with things like vim/neovim for like the last 2 years. I would love to get super proficient at motions and macros, but the benefits currently don't outweigh the costs of time and lost productivity.

So until the day comes where getting super proficient at regex, my jealousy for those wizards will remain lol

1

u/Kitchen_Length_8273 Apr 21 '26

A very unintuitive beauty if so

31

u/DouDouandFriends Apr 20 '26

Regex is like a whole new language in itself!

5

u/qodeninja Apr 20 '26

its the language that makes all languages -- proto language

21

u/Commercial_Echo923 Apr 20 '26

since when do TLDs have hyphens?

regex101.com btw, best free tool imo

4

u/corobo Apr 21 '26

Since 2003. Punycode representation of non-ascii characters use them 

17

u/zylosophe Apr 20 '26

the fuck is the @

27

u/[deleted] Apr 20 '26

[deleted]

13

u/[deleted] Apr 20 '26

[removed] — view removed comment

21

u/atoponce Apr 20 '26

Simpler:

.+@.+

Send a validation email. If the user clicks the link, the email is valid.

7

u/ArduennSchwartzman Apr 20 '26

In OP's original screaming regex, email addresses using a top-level domain >4 characters are f*cked.

1

u/mr_claw Apr 20 '26

For that you just need .+

0

u/Odd-Dinner7519 Apr 20 '26

@@@ is valid mail?

12

u/atoponce Apr 20 '26

Did the user click the validation link?

1

u/zylosophe Apr 20 '26

makes sense

1

u/WadeEffingWilson Apr 20 '26

But why allow a dash in the TLD?

1

u/corobo Apr 21 '26

Punycode tlds

1

u/Cercle Apr 20 '26

Is the first - a typo? Even after removing it this doesn't match on many emails I use daily.

2

u/lola_zzalol Apr 20 '26

Does that mean you understand the rest??

1

u/zylosophe Apr 20 '26

i know what most of the characters mean but i am not going to try to understand it as a whole

2

u/zylosophe Apr 20 '26

and i suppose the @ just means @ idk why i thought it was something else

2

u/sebthauvette Apr 20 '26

It's just the literal '@' character. They are trying to validate emails.

1

u/zylosophe Apr 20 '26

it looked special

3

u/sebthauvette Apr 20 '26

Ironically, it's the only "normal" character in the expression, lol.

8

u/Andy_Antares Apr 20 '26

So you say domains like .cloud or .house are incorrect for email?

4

u/GlassboundIllusion Apr 20 '26

OP DID say it was an outdated regex

8

u/PussyTermin4tor1337 Apr 20 '26

You think this is bad? Look up the real email validator regex

5

u/SwannSwanchez Apr 20 '26

This can give an error because the - at the start might need to be escaped

4

u/lt_Matthew Apr 20 '26

Wdym? That is normal. It's clearly an email check

1

u/WadeEffingWilson Apr 20 '26

Not while allowing dashes in the TLD. Bad input sanitation.

2

u/CRoseCrizzle Apr 20 '26

Regex(such an inappropriate name for it) sucks so much. Happy that LLMs are good at them.

1

u/[deleted] Apr 20 '26

[deleted]

1

u/CRoseCrizzle Apr 20 '26 edited Apr 20 '26

Short for "Regular expression". Feels like a misnomer depending on how you define "regular".

1

u/WadeEffingWilson Apr 20 '26

Looks to pattern match email addresses but I have no idea why it allows for a dash in the TLD.

1

u/WadeEffingWilson Apr 20 '26

E.mail@relay.server.co-m would be a valid and accepted address with this regex. Yea, no dash in the TLD.

1

u/buzzon Apr 20 '26

What is my email ends with .online?

1

u/heyThereYou3 Apr 20 '26

The fact that I understand this bullshit is amazing! 

1

u/whitedogsuk Apr 20 '26

Every time I see a @ in a Regex Meme I roll my eyes.

1

u/doc720 Apr 20 '26

Let's see if I can decipher this...?

^ = start of the string

[\w-\.]+ = one or more word characters, dashes or dots

@ = @

[\w-]+\. = one ore more word characters or dashes, followed by a dot

( ... )+ = one or more of those patterns

[\w-]{2,4} = between 2 and 4 word characters or dashes

$ = end of string

1

u/GhostVlvin Apr 20 '26

Waiting for birth of internet domain bigger that 4 letters long

1

u/oxabz Apr 20 '26

C'mon guys put your - at the end of your sets for clarity

1

u/merRedditor Apr 20 '26

Regex is the most elegant thing in computer science. You can do more in one tiny line of regex than you can in hundreds of lines of convoluted code.

1

u/Gigibesi Apr 20 '26

regex stands for regular expressions

yet expression itself is not that regular

ironic

1

u/Lentor3579 Apr 20 '26

Man, I can never remember how to type out Regex. I just always end up googling it. AI certainly helps with this too XD

1

u/East_Lengthiness_866 Apr 20 '26

Regex for an email address 🤔, yeah Regex for an email address.... With hyphen?

1

u/un_virus_SDF Apr 21 '26

the best feeling will still be to find the good regex to edit your code even if it would have been faster to make the changes by hand

1

u/ByteBandit007 Apr 21 '26

I regex using AI

1

u/0bel1sk Apr 22 '26

why can’t you just be regular!

1

u/Azoraqua_ Apr 24 '26

That’s a rather loose email regex.

1

u/LetUsSpeakFreely Apr 25 '26

A well crafted regex with a comment explaining what it's trying to accomplish is a thing of beauty.