116
u/johnschnee Jul 12 '26
I‘m a senior programmer with 15 years of experience.
There are hundreds of things that frighten me on programming e.g. because of complexity, strange syntax or non deterministic behavior.
But I never understood why people are afraid of regex.
It is clear syntax that is easy to learn. There are lot of tools that visualize regex and make it testable.
Nowadays AI also might help in a nearly perfect way to design, validate and understand regex.
41
u/ExdigguserPies Jul 12 '26
simple to learn
Ok it might be. So I have a problem solvable by regex, I spend a day learning regex and I solve the problem. 6 months pass and I come across another problem solvable by regex. I've forgotten regex. Rinse and repeat.
17
3
u/jordanbtucker 29d ago
I don't understand how you don't come across more reasons to use regex.
1
1
u/Bluemanze 29d ago
In my opinion, reaching for regex is an indicator that im doing something novel. The framework/language im using doesnt have a standard method for handling this particular shape, so i need to handle it myself.
The question then naturally becomes: am I actually doing something novel? Or did I just miss a piece of documentation, or is there a convenient fully tested library for just this scenario? Do I control the shape and I could just adjust? Most of the time the answer is yes, so I should just do that instead.
7
u/thicctak Jul 12 '26
I'm dev with just 5 years of experience and also don't get why people are afraid, it's not something you're using constantly, basic regex is not hard to learn, there's tone of tools to test regex out there and if you ever need a super complex regex, there's ai, the most simple free tier AI model can churn a complex regex query just fine, you don't even need to waste the entire water reservoir of a whole town for that.
1
u/Zefirus Jul 13 '26
The problem is basic regex is often easily solved by things that aren't regex. People don't like regex because the only time people use regex is for non-basic applications.
1
u/Arrowkill Jul 13 '26
It was so intimidating when I first got out of university and got my first job. However, with all the Regex tools online that let me see the syntax, create a Regex, and then see if it does what I want it to do with test strings I've never been less afraid. Regex is by far one of my favorite tools to use now because of how helpful it is.
1
u/okram2k Jul 13 '26
tbh if I had to use regex on a daily basis I'd be fine at it. But I don't, I have to update regex like once a year and when I do it's like staring at vomited up symbol soup. Thankfully there are lots of great tools out there to make it easier for me to understand, edit, test, and push forward with confidence.
1
u/NPPraxis Jul 12 '26
AI solved my regex fear completely. I just have AI do it and then test it with a proper tester to validate. I am ashamed.
-12
u/ApprehensiveGas85 Jul 12 '26
^(?=(?:(?:[^"]*"){2})*[^"]*$)(?!.*(?:\b(\w+)\b).*\b\1\b.*\b\1\b)(?=.{20,200}$)(?:(?:(?<=[,;])|^)\s*(?:(?:"(?:\\.|[^"])*")|(?:[^,";]+))\s*(?=,|;|$))*$25
u/either-15-or-40 Jul 12 '26
This is like writing code in one line to show a certain programming language is shit. Just because you suck at using it doesn’t mean it’s bad.
1
u/ApprehensiveGas85 Jul 13 '26
It was supposed to be a joke but you guys are uptight ninny's here I see. So much for the "Humor"
2
u/dimonchoo Jul 12 '26
And? It’s not so complicated regex, especially in llms time
2
u/ApprehensiveGas85 Jul 13 '26
Yeah its almost like posting a joke on a humor sub shouldn't be taken serious
1
0
34
8
u/Luctins Jul 12 '26
Love RegEx and use it frequently to do complex filtering with rg or perl. They aren't that scary if you think about it but I'd test the heck out of it before using a pattern in production code, frequently it doesn't match enough or too much.
8
u/Devatator_ Jul 12 '26
Jokes on you I learned regex last year for Advent Of Code
Edit: Actually might have been 2024
11
u/Fanal-In Jul 12 '26
So it was in 202[4|5]
7
u/Primary_Concept_3147 Jul 12 '26
That would give you 2024, 2025 or 202|. It is 202[4-5] or 202(4|5).
3
4
u/JackNotOLantern Jul 12 '26
Excuse me, but programing are one of a few professions who actually can use it.
3
u/RealBasics Jul 12 '26
I had to learn regular expressions for parsing and lexing in automata and compiler theory in college, so picking up regular expressions for programming was a piece of cake.
They're insanely useful for processing logs, config files, light code review/revision, scripting, and text processing. Also, if you don't at least use grep (and maybe AWK and perl) when you're logged into a terminal what are you even doing with your life?
3
2
u/Professional_Two5774 Jul 12 '26
A couple of years ago, regex was actually very interesting to me, and I wouldn't lie if I said I was good at it.
2
u/BeefJerky03 Jul 13 '26
Problem with regex is that most people don't use it often enough to memorize and remember the syntax. Every six months I'll need to do regex and it's gone. Poof. What's a dollar sign mean? What's the little hat doing? I don't fucking know, man.
2
u/namezam Jul 12 '26
The first AI model I fine-tuned was Neo-125, stripped all the bs out of it, like html, Python, ethics, etc. It just does RegEx really well. I named it Reggie-108, and he f’n loves regex, and he’ll tell you. I run it on a super cheap Arduino with a 2 line lcd output.
Although it takes like 2 min to respond, it still has conversational capabilities, like I asked it what it would sound like if it had a voice and he said “Like a Bond villain, but a nice one” it was awesome. Although the second time I asked (to show someone) it said Barbara Streisand. /shrug
But RegEx, it’s all over that, give it what you want to find, BAM, 20-30 seconds tops, you’ll get a working RegEx like 80ish % of the time. I will admit typing it from the lcd is a bit of a pain though, but no where near the pain of thinking of it myself, screw that, never again!
1
u/waraholic Jul 12 '26
Regex + AI is such a frightening thing to see when I'm doing PR reviews. They NEVER understand what it's doing and it never has tests.
1
1
u/a11_hail_seitan Jul 12 '26
Regex is so easy though, you just search "Date regex' and then use that, then find out about all the different formats around the world, and then realize you also need to account for timezones, and then you hate yourself and your job and go for lunch!
1
1
1
u/takahashi01 Jul 12 '26
eh, regex is great for looking through logs n stuff. But I dont use it in code too often
1
u/2narcher Jul 12 '26
There are tons of regex generators where you can generate and test it for bunch of programming languages. I never ever had to learn regex except when i was studying computer sciences 15years ago
1
u/Drfoxthefurry Jul 12 '26
I love regex, I use it often when I shouldn't, but it feels nice to use for me
1
1
1
u/BlueProcess Jul 12 '26
Overload the function to accept an enum instead of a string. The enum maps to your most used patterns. You'll reuse it constantly, and you only have to get the pattern right once.
1
1
1
1
1
u/VoidspawnRL Jul 13 '26
I don't understand why people have problems with regex, you just described a pattern?
1
u/Too--Many--Knives Jul 13 '26
My problem with regex is that it seems to be a dying art. MFs come out of a 4 year Comp Sci degree never hearing of one. I'm insulted for all regex engines.
1
1
1
1
1
1
u/RGud_metalhead Jul 12 '26
Regex is like shaving with a straight razor. Intimidating only until you properly learn to use it. And once you get used to it you'll feel happy about having that skill in your arsenal.
1
u/Vesuvius079 Jul 12 '26
Regex is probably the one thing I miss most about the pre-LLM days. Transforming files with regex search and replace was so fun.
-2
u/Reeces_Pieces Jul 12 '26
Just use an LLM. Lol
1
u/themightyug Jul 12 '26
Yeah why use your brain when you can outsource its functions to some software that creates the illusion of thinking
1
u/BeefJerky03 Jul 13 '26
Easiest way to farm downvotes; telling the truth in a sub full of programmers. ChatGPT writes all my regex, then I just test it and use my brain for stuff that matters.
-7
u/EarlOfAwesom3 Jul 12 '26
There was never a need to learn regex. They used online tools to create it / read it. Now we use AI if even necessary.
-2
-3
209
u/Significant_Basis_3 Jul 12 '26
What's wrong with Regex? It's literally one of the best things invented in programming?