Regex seems to have a broad array of love and hate. How do you feel about it? Do you seek to use or avoid it as a problem solver, and how much do you understand it?
For further actions, you may consider blocking this person and/or reporting abuse
Regex seems to have a broad array of love and hate. How do you feel about it? Do you seek to use or avoid it as a problem solver, and how much do you understand it?
For further actions, you may consider blocking this person and/or reporting abuse
Dmitry K -
Archie -
Luxand.cloud -
Dev Leader -
Oldest comments (67)
Works great in my terminal and editor. I can search for something till it looks right, then replace it with what i want.
It production code its so hard to see all the edge cases. As a Data Engineer performance is about last on my list of metrics, as most of what I do is run on a schedule, not when someone clicks it, so an extra 5s on a 10 minute run is no big deal. With that said every time I see a regex in a code review I ask can we do this without a regex, even with a huge performance hit, or write tests for every possible edge case we can brainstorm.
You write a regex and don't write a comment next to it describing what it does, you and I gonna have a lil' chat ;)
I recently had a case where the person I was reviewing added regex, and they did comment what it did well, and honestly the comment looked exactly correct. They were missing tests, and it wasn't until they ran tests that they realized that what they had done was not what they described in the comment.
Hey, tests go without saying, right?
;)
As long as it can be tested proven, and injectable (i.e. not hard coded) should be fine? :)
It's something I use often, but still 100% only copy from Stack Overflow.
I don't write regex. I look up what I need to when I need it and I never think about it again. π€£
I've found that the specificity of what I need when I do need it can vary so vastly, and that the library for it is so large, that the best use of my time is figuring out what I need at that specific moment and moving on.
It's not needed often enough to warrant full deep dive into it, for me at least.
If you're here and want to learn more about regex (regular expressions)...
Getting Started with Regular Expressions
Nick Taylor γ» Jul 18 '21 γ» 4 min read
I love working with Regular Expressions.
I use them frequently in VS Code and have a few articles out here on implementing them for Search-and-Replace.
I had a project where I had to replace an AS400 Custom Script Search Language with a JavaScript version. I quickly learned how slow they are when running hundreds of them per line. It also prompted me to create a new tool for documenting Regular Expressions (github.com/bob-fornal/reggie-docs).
Regex was my second programming βaha moment.β I love regex, all thanks to Apacheβs mod_rewrite way back in like 2004.
I admit, when I first became really fluent in RegExp, I tended to overuse them for some time. Even now, I have the impulse to solve string-based issues with RegExp, but I have learned to stop and think about if they really are an improvement over other solutions. So you could say I seek to use it and try to avoid it at the same time, mostly because I understand it.
A few years ago I bought a book (I can't find right now) about the theory of computation, and it started with finite deterministic automata (FDA), moving on to non-deterministic finite automata (NDA) and how FDA and NDA are mathematically equivalent, then it showed how to turn NDA into regular expressions.
The explanation opened my mind to a new way to look at regex, so I found it a lot easier to understand and write them, and also understand their limitations.
The main issue I'm left with is that regex engines these days have added look-ahead and look-behind which means they are no longer mathematically equivalent to NDAs.
I like it but I tend to tell people to avoid it if possible just because it makes code hard to read.
If people on the team do use regex I ask them to include a link to regexper.com/ in a comment.
It generates a flow chart like this one.
I didn't know about one. definitely useful. Thanks for sharing.
Oooh. I like this tool you introduced upon everyone.
Personally, if a regex is confusing me, I'll just pop over to regex101 for a quick test. It's also a great tool.
I prefer regexr.com because regex101 is not embeddable in figjam document figma.com I use to keep code notes as it supports code blocks.
Other tools I find pretty but buggy for complex regex are :
regexper.com/
jex.im/regulex
extendsclass.com/regex-tester.html
Now, this is really cool and useful - thank you!!
Wow thanks for sharing that tip.
Have tried them all I think, that one is nice but it doesn't work for very complex regular expressions (like with some lookaround expressions) whereas it works with regexr.com
didn't know that service, seems awesome, also worth a try cucumber.io/docs/cucumber/cucumber..., makes regular expressions more human friendly and readable
I love using regular expressions. And try to adopt the following pattern:
Regular expressions can be quite dense to read, so I want to use the tests to highlight my expectations around what I wrote.
If I can avoid it in my code, I will. They can grow like crazy overtime, and they become difficult to read and understand.
I love them in my editor (I use Vim btw) or to perform operations in the shell, however. It's super powerful for everything plain text: search, search and replace, repeating an action on specific lines... the list goes on.
I like to use Regex and I use it frequently but not for anything too complicated. I generally build all my RegEx from Regex101.
I really understood it at its core during my university Computer Science Program where we talked about DFAs -> NDFAs -> Regular Languages -> Regular Expressions
Hmmm...I would advise to use it only for search, data scrapping and data validation/cleaning purposes. Beyond that I won't advise anyone to use it unless there's a real reason to use it like to reduce the complexity of your code for the above purposes.
Plus there's tons of websites that allows you to copy and paste regex for specific uses depending on your language of choice or regex engine you are using.
To me it's sort of like Leetcode, readability is a issue unless you had learnt it but beyond that it kind of being too clever with your code.
I like how regex makes it easier with the task, but personally I really don't understand it most of the time. But I will try my best to learn it.
Some comments may only be visible to logged-in visitors. Sign in to view all comments.