

I can't imagine any programmer has memorized all of regex and the expression, including grouping / group naming, backtracing, and all that. But if something goes wrong, debugging a regex is not easy for most people.Īlso, because regex is not used that often, it means you need to look it up each time. Regex is not easily read, it is often a lot of upfront work, then hoping / testing to make sure it works right, and then it is set. On the flipside, someone who is using it just because is also a red flag. TLDR: I don't use it enough to know it by heart and I've got other shit to do now. While confirming that an email is the correct format is still needed, it's such a tiny task relative to everything else that needs to be done, it often feels like "why am I spending time on this?" Spending an hour or two putzing with regex no longer feels like a good use of my time. Now I'm working on much larger tasks like "create a service to handle user authentication". In a task like that, if you're using a regex, creating a regex that that understands the format of an email is at the heart of the task. A random example would be "Take this user input, confirm it's an email, and if not, return an error". Early on, my tasks were small and self contained. I actually write a new regex maybe once a year at most.Īs I've progressed in my career and the problems I'm solving have gotten more complex, spending time dealing with the tasks that regex solves feels like more and more of a hurdle toward my end goal. If I have something that regex could solve, often times there's a library that can do what I need or someone else has already written the regex I need somewhere else in our codebase. There was a time when I knew all the little tricks, but like a language you learn in high school, it's easy to forget them when you're only using them once or twice a year.

In my daily work, I don't use regex enough to really memorize. I think there are two reasons why my opinions have changed and I think they are big factors in why people "hate" regex: I wouldn't say I hate it, but any time I have to do anything regex related, I find it tedious and a bit frustrating. Now, almost a decade later, my opinion has changed. I would play regex golf and solve regex questions on stack overflow for fun. It kind of felt like a programming crossword puzzle or something like that. There was a time early in my career where I really enjoyed regex. You can do all sorts of wild shit here and save time, but think hard before putting the crazy stuff in a codebase.

Also great with commands like sed to sort through data and extract the useful bits. Where regex shines is in your throw-away work - I use it in vim all the time as it drives vim's search/replace engine.

Also, it's never a substitute for XML or CSV parsing. It's worth the effort to keep it clear and straightforward, and even substituting your language's string library for things if it's more readable. When regex lives in code, you have to be able to read and maintain it. Like wildly overcomplicated homegrown email validators that are both 1) wildly complicated and 2) still don't work right. The hate I have seen is usually justified and aimed at specific abuses of it. It's a super powerful but clumsy tool, so different developers definitely have different levels of aptitude and attitude towards it. In my career, I haven't seen a ton of hate for it.
