Regex – Why are regular expressions so controversial?


When exploring regular expressions (otherwise known as RegEx-es), there are many individuals who seem to see regular expressions as the Holy Grail. Something that looks so complicated – just must be the answer to any question. They tend to think that every problem is solvable using regular expressions.

On the other hand, there are also many people who try to avoid regular expressions at all cost. They try to find a way around regular expressions and accept additional coding just for the sake of it, even if a regular expressions would be a more compact solution.

Why are regular expressions considered so controversial? Is there widespread misunderstandings about how they work? Or could it be a broad belief that regular expressions are generally slow?

Best Answer

I don't think people object to regular expressions because they're slow, but rather because they're hard to read and write, as well as tricky to get right. While there are some situations where regular expressions provide an effective, compact solution to the problem, they are sometimes shoehorned into situations where it's better to use an easy-to-read, maintainable section of code instead.