When Are Regexes Appropriate?


Regular expressions are useful enough that they’re built in to the syntax of the shell. But they’re not always the right tool. Here’s my off-the-cuff heuristics for when to use them.

If there is any sort of arbitrary nesting (like nested quotes and parens) and you need perfect accuracy on all sorts of inputs, don’t use regex.

If the input isn’t pathological, if accuracy isn’t required, or if you need speed, use regex.

Related Posts

How I feel about ebooks

List of places where the US has been involved in regime change, with multiplicity

Accuracy vs Precision

Handy command line benchmarking tool

Stan Rogers

Ultimate Hot Couch Guy

Quote on Java Generics

The Programmer Tendency

Figure out undocumented JSON with gron

Mental Model of Dental Hygiene