3 ms·
Please don't use regexes.
by alayne 13y ago
Please don't use regexes.
- 83a 13y agoso how do you e.g. remove trailing whitespace?
- alayne 13y agoIs that a serious question? Almost every major language has some kind of string trim/strip function for that purpose.
- 83a 13y agogood point. missed that. but does your text editor have a trim function, too? i've thought of a case i used a regex the last time. and it was removing whitespace in some code file.
- kbrowne 13y agoEver? For any purpose whatsoever? That seems overly prescriptive.
- alayne 13y agoSure, for scripts, adhoc analysis, command line hacking and whatnot, go ahead. Regexes should be seen more like a last resort than a good software engineering choice. They're a code smell. I have seen so many incorrect, slow regexes from people who don't know what they are doing that I have to recommend as a best practice that you don't use them unless you are going to study automata, read Friedl's book, the Dragon book, and study with Tibetan regex monks for years, and mentor everyone who has to maintain your code until you die.