Search code examples
regexlanguage-agnostic

Are regular expressions worth the hassle?


It strikes me that regular expressions are not understood well by the majority of developers. It also strikes me that for a lot of problems where regular expressions are used, a lump of code could be used instead. Granted, it might be slower and be 20 lines for something like email validation, but if performance of the code is not desperately important, is it reasonable to assume that not using regular expressions might be better practise?

I'm thinking in terms of maintenance of the code rather that straight line execution time.


Solution

  • Whenever i use a Regex i always try to leave a comment explaining exactly how it's structured because I agree with you that not all developers understand them and going back to a regex, even if you've written it yourself, can be a headache to understand again.

    That said, they definitely have their uses. Try stripping out all html elements from a box of text without it!