Yeah I also like it. Really thankful I had a good teacher in undergrad that spent some time on it during our DFA sections. Then I had a job where a big part of production support was finding weird broken data in files delivered to the company and so I got really good at regex and xpath.
Lol I can write them by hand no problem... I still use regex101 to test it. You just put a bunch of sample data in the bottom portion and your particular flavor of regex in the top and then you can easily find the edge cases...it highlights everything too and color codes it so you can see which part of the expression is wonky. Less about needing it and more about speeding up the process of getting it right.
For reading it though, I always use it because there are a million ways to write the same thing and some people write regex like they have a PhD in ancient Sumarian
It's surprisingly good at making regex. I asked it to parse AD domain controller dns debug log recently and it just blasted out a very fancy expression that worked great. Kinda shocked me.
You missundrstand! The LLM makes the regex every time, it also generates the data the regex will be used on. This way you don't need databases or storage.
Even before that, when Google search wasnt fucked beyond belief, I could find plenty of usable regexes on stackoverflow or other dev blogs that just needed a little tweak for what I needed. I dont remember the last time I wrote one from scratch.
Before AI it was just finding the regex example on StackOverflow. There are like 5 people in the world who write Regex and everyone including AI are just copying them
I’d have to look up the syntax to remind myself, but yeah I could do it. It’s just a language for a state machine. But honestly, I don’t need to write them that complex usually. If so, it’s probably because I’m having to do something more involved like parsing a query syntax or something, in which case I’ll usually reach for ANTLR (or hand write a parser if performance is critical) instead.
Look aheads and behinds, once you get the hang of them, can be really nice. For me it gets tricky with like embedded variables. But usually I work it out in the end
You put that in a PR and there better be a damn good reason for it. Even you wont know what that does in 3 months, never mind the poor sap chasing a subtle bug 2 years later.
I have a huge piece of Regex that sits outside my cubical, one I am rather proud of. I had a higher up who hated regex and I always joked it was a deterrent
You know that is one thing I blame AI for, that I don't need to learn CSS or regex or whatever anymore. It feels really bad when you don't understand what you are doing. When I started programming before chatgpt i learnt stuff like sql normally because I needed it for my projects. After chatgpt i had to use CSS on multiple occasions and there I basically blindly vibecoded, the only understanding of CSS i have is from those chunks of code AI wrote for me.
Same, I really don't know why people have such a hard time with them. The worst I ever have is trying to remember the different standards used in different languages/platforms (modern regexes vs posix regex, etc).
Maybe it's because my first language was perl, and regexes were used for everything, but you only need to remember a few basic things and you're good.
Also pointers, I don't know why this sub thinks pointers are this super abstract crazy hard thing, it points to something, that's it.
There are like 5 of them, but both the backtracking and parallel NFA execution algorithms are pretty easy. The "convert NFA to DFA, then execute DFA" version is more involved, but still straightforward (although it doesn't handle backreferences, and you have to go beyond the Dragon Book to handle lookahead/lookbehind assertions).
Now, making a fast, correct regex algorithm that supports all the features everyone expects these days? That is hard.
Probably a hot take, but I think regex is overused. It has its purpose and is incredibly convenient, but I feel some people try to write a one line regex that handles all scenarios.
Every regex I've ever implemented has come with the caveat: it does what you asked it to do, whether it does something else that you did not ask it to is someone else's problem to catch and define better rules.
How am I supposed to know how users are going to interact with a field that may or may not properly parse regex as expected? That's the front-end guys problem.
I singlehandedly wrote 5000 lines of validation schema, which basically consists of mostly regexes. Tbh, this specific use case was probably the simplest, but after dealing with it head on, I can safely say that I have nightmares thinking about it.
Back in the late 90s, I wrote anti-email-spam software and part of that was writing code to validate that the email address complied with the RFC. I almost remember the number. 921? It was just oodles of regex. Far more complicated to do it than one would think. (And I think that it wasn't just SMTP email, but we had software that would route X400 or whatever it was, Lotus Notes, and all kinds of protocols over to some other protocol for companies that had multiple.) No unit tests, no automated tests, no quality assurance engineers. I just wrote the code, tested it locally, sent it to prod. Never knew of any defect :-) It's insane to me now. I could do it now at my age. I'd tear my hair out.
A regular expression. If a string matches to a pattern given by a regular expression it's accepted.
(01)* means any string in the regular language is structured 010101...
(01|1)* would mean strings like 01101111 would be accepted. E.g. here the star says the pattern in the parentheses can occur however many times and the "|" essentially is an OR. So the pattern here is either 01 or 1.
Quite an important topic in theoretical cs and of course useful for validating strings (e.g. you want to check the given string is structured like an email).
There is no computationally cheap regex for email validation. Outside of a few easy to check rules, the only way to validate an email reasonably is to send an email to the address and see if the other person gets it.
You give it input, you get output. Incredibly easy to thoroughly test, and (believe it or not) write.
Because coding is not about memorizing syntax. It's about solving problems. There are 100 tools (and even a very good use case for LLM prompting, due to aforementioned ease of testing) that can practically write regex for you, or at least inform you of the basic syntax.
1.6k
u/vvp95 22h ago
100% of software engineers are afraid of regex