Skip to content

Comment on Stop avoiding regular expressions damn it

Comments

The core criticism of regular expressions is legitimately directed at intermediate programmers who know enough to be dangerous, but is sometimes inappropriately cargo-culted by beginner programmers who use it as an excuse not to learn regular expressions.

The fact is that despite pithy slogans, there is a sweet spot where a regular expression does the job of matching a string in a clearer fashion than anything else. But that sweet spot is well shy of the theoretical power of regular expressions (especially in Perl!), before which you should further your understanding of a range of parsing techniques before hacking together a baroque regex.

Though there's nothing wrong with busting out a baroque regex in one time use contexts (editor's search function, throw-away application of grep or sed, &c).

Of course not.

As with many things, I find the sweet spot changes depending on my knowledge and familiarity with the concept.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.