this post was submitted on 12 Nov 2023
258 points (95.1% liked)

Programmer Humor

32174 readers
93 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 

all 50 comments
sorted by: hot top controversial new old
[–] [email protected] 61 points 10 months ago (1 children)

This is proof that regex even confuses the bots.

[–] ik5pvx 15 points 10 months ago (1 children)

May be our own path to survive the AI rebellion.

[–] kautau 10 points 10 months ago

Maybe the goal wasn’t to stop the AIs but the aaaaaaaaaaaaaaaaaaaaaaaa! we made along the way.

(For reference: https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS)

[–] [email protected] 37 points 10 months ago (12 children)

I still don't understand regex at all

[–] [email protected] 54 points 10 months ago (1 children)

I recommend using https://regex101.com/

It explains all parts of your regex and highlights all matches in your example text. I usually add a comment to a regex101 playground if I use a regex in code.

[–] [email protected] 38 points 10 months ago (2 children)

Regexes are write-only. No one can understand other peoples regexes

[–] [email protected] 7 points 10 months ago (1 children)

Not only other people's regexes. Mine from last week and before too

[–] [email protected] 2 points 10 months ago
[–] [email protected] 3 points 10 months ago

That's also 'cause other people's regex are garbage!

[–] [email protected] 37 points 10 months ago

The plural of regex is regrets.

[–] [email protected] 23 points 10 months ago (2 children)

My guess is, that someone started with a small share of features to find a simple solution for the problem, but the complexity of the problem got waaaay out of hand.

[–] [email protected] 22 points 10 months ago (2 children)

Regexes are actually used in formal computer science (if that's the right term), i.e. "proof that this and that algorithm won't deadlock" or something like that.

They're actually really elegant and can cover a lot. But you'll have to learn them by using them.

[–] [email protected] 4 points 10 months ago* (last edited 10 months ago)

For the purpose of algorithm verification, the final and/or pushdown automaton or probably sometimes even Turing Machines are used, because they are easier to work with. "Real" regular expressions are only nice to write a grammar for regular languages which can be easily interpreted by the computer I think. The thing is, that regexs in the *nix and programming language world are also used for searching which is why there are additional special characters to indicate things like: "it has to end with ..." and there are shortcuts for when you want that a character or sequence occurs

  • at least once,
  • once or never or
  • a specified number of times back to back.

In "standard" regex, you would only have

  • () for grouping,
  • * for 0 or any number of occurances (so a* means blank or a or aa or ...)
  • + as combining two characters/groups with exclusive or (in programming, a+ is mostly the same as aa* so this is a difference)
  • and sometimes some way to have a shortcut for (a+b+c+...+z) if you want to allow any lower case character as the next one

So there are only 4 characters which have the same expressive power as the extended syntax with the exception of not being able to indicate, that it should occur at the end or beginning of a string/line (which could even be removed if one would have implemented different functions or options for the tools we now have instead)

So one could say that *nix regex is bloated /s

[–] loafty_loafey 3 points 10 months ago (1 children)

You are probably thinking of Temporal logic which allows us to model if algorithms and programs terminate etc! It can be represented by using state machines tho!

[–] [email protected] 2 points 10 months ago (1 children)

It's been a while, so I'm quite rusty, especiallyeon the terminology, but I think we modelled feasible sequences of finite and infinite state machines using regexes.

That's how I was forced to learn 'em in uni. ;)

[–] loafty_loafey 2 points 10 months ago

Ohhh I must be confusing the two! But yea, Regex is just NDAs in text form! The course I have had on it is one of my favorites! Really fun stuff

[–] loafty_loafey 19 points 10 months ago

Regex is actually just a way to write (Epsilon) non determistic state automata(ε-NDA) using text! ε-NDA comes from automata theory and they are just a somewhat powerful way to describe state machines! They can kind of be seen as a stepping stone to things like Context-Free Grammars which is what language parsers use to define their language/parsers, and Turing machines! Regex is a fundamental part of computer science, and they are of course incredibly useful in string validation due to their expressive power! If you study at uni and get the chance to take a course in automata theory I recommend it! Personal favorite subject :)

[–] FooBarrington 16 points 10 months ago (1 children)

It's really not too bad as long as:

  • you use a proper IDE (e.g. Regex101) with highlighting and piecewise explanations

  • you use named capturing groups

  • you give the regex a descriptive name in your code

[–] blackbirdbiryani 3 points 10 months ago

People write regex in notepad and complain it doesn't work on the first try...

[–] qaz 8 points 10 months ago (2 children)

What part do you not understand?

[–] [email protected] 9 points 10 months ago (1 children)
[–] qaz 5 points 10 months ago (1 children)

So you do not understand nothing? That's great to hear.

[–] [email protected] 4 points 10 months ago (1 children)

No, No, they don't understand everything and nothing!

[–] qaz 3 points 10 months ago

Both statements match 😄

[–] [email protected] 2 points 10 months ago
[–] [email protected] 5 points 10 months ago

//////?-.,", duh,?!

load more comments (3 replies)
[–] [email protected] 31 points 10 months ago

Error in Moderation

Could have been worse. Could have been an Error in Excess.

[–] [email protected] 30 points 10 months ago (4 children)

Regex's are not something you need AI for as there are already tools that explain them for you. Use regexr.com or a similar tool.

[–] [email protected] 17 points 10 months ago (2 children)

Regex's

Foxes

Boxes

Hexes

Regexes

You can do it. You too can pluralize without an apostrophe.

[–] MajorHavoc 4 points 10 months ago

I've begun to understand that the modern meaning of an apostrophe is "oh shit! Here comes an 's'".

Sadly, I am gradually growing okay with that idea.

[–] [email protected] 1 points 10 months ago

Thanks for pointing that out, it's a bad habit I've picked up!

[–] [email protected] 7 points 10 months ago (1 children)

____ are not something you need AI for as there are already tools that explain ____ for you. Use Wikipedia or a similar tool.

[–] [email protected] 1 points 10 months ago* (last edited 10 months ago)

I don't agree that AI has no uses, you just have to know when to use it. There are multiple times I have scoured documentation and official forums of a niche tool to few results only to ask ChatGPT and get far closer to my goal in 2 minutes than I did in 30. I know the AI has to be getting that info from somewhere, but if Google, Reddit, and a forum search can't find it then I am sorry but I am going to ask an AI.

[–] [email protected] 3 points 10 months ago

Yeha, also anything else has plenty of books and internet content on them so you really don't need AI for those too.

[–] deafboy 1 points 10 months ago

Groups multiple tokens together and creates a capture group for extracting a substring or using a backreference

With an explanation like this, I thing I'll take the AI.

[–] [email protected] 14 points 10 months ago* (last edited 10 months ago)

You have a problem. You decide to use regex to solve it. Now you have two problems.

[–] [email protected] 8 points 10 months ago (1 children)

I got the “error in moderation” today today too when I asked it to make me a ghost with the beard and body type of Santa Claus. Like it knows Santa is not a real person right?

[–] [email protected] 3 points 10 months ago

Ya, it's a generic error from the looks of it. Didn't know what error to throw when it went down, so it appears to have defaulted to this.

[–] Presi300 1 points 10 months ago* (last edited 10 months ago)

Regex can be explained? I thought it was all just arcane runes, only understood by the 60 year old unix wizards, who created it in the 1st place....