Hacker News new | ask | show | jobs
by nightbrawler 1674 days ago

  [0] Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
I love regular expressions and figuring out the syntax to solve problems I encounter where I can use regex. Such as searching code for calls with specific named params that may be in different order across the code base. But I always have this quote in the back of my mind if I'm thinking about using regex in code, especially areas that get hit a lot.

[0] https://blog.codinghorror.com/regular-expressions-now-you-ha...

2 comments

It's really subject-specific. What I usually see is a small problem easily solved by Regex, that a few months later down the line we need to expand the regex a little bit, but that's ok it's still readable... repeat this a bunch of times and now you have a critical regex line that nobody really understands how it works and nobody ever wants to touch without it being unit-tested to death.

It's just a riff on tech-debt, imho

We need a natural-language <-> regex translator
I am a huge, huge fan of https://regexper.com/ - paste pretty much any regex, and it will generate a visualization of what it does. It's been invaluable even just as a sanity check, it just makes it so easy to trace the flow of what a pattern is doing.
Back when I used Windows, I had an app called Regex Buddy and you could paste in any regex and it would generate a comment block that broke down what was going on. Was super useful when you come back a few months later and need to understand a complex regex
I once asked my friend: "Is there anything Regex can't do?" He replied: "Work the first time?"

And that's how I always think of Regex now. It's an incredibly powerful tool that I pull out pretty often, but if I'm doing anything beyond the most basic pattern matching I know I'm about to lose a bit of time questioning my abilities and sanity.