top | item 35380080

(no title)

Shindi | 2 years ago

If you're using a regex it's a smell that there is a better tool for what you need to do. A ton of if statements is a much more readable way of writing code than regex.

discuss

order

zamnos|2 years ago

Respectfully, no. If you're trying to write a full blown language parser then regexps are the wrong tool, but a 50 line function doing the job of a regexp has a really funky code smell. Comment your regexps*, and use a parser when your usecase outgrows regexps, but a blanket ban on regexps smells of "I'm not smart enough to understand them".

* https://www.oreilly.com/library/view/regular-expressions-coo...

encryptluks2|2 years ago

Unfortunately regex is the best we have. A bunch of if statements is also a whole less efficient and prone to errors than a regex statement. Once you start to learn regex, it actually isn't that bad. The challenging part is that a lot of people cut and paste not really understanding it and you end up with a bunch of bad regex examples.

jwestbury|2 years ago

Eh, I think the challenging part is understanding a complex regex that's already been written. You really do need good comments and unit tests to go along with a regex in order to understand the intent, otherwise they rapidly become unmaintainable.