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 to change tabs to spaces

Another Way to Write Conditional Probability

Notes for May 9, 2019

A tool to look at random images

Safeway

e-ink reminisces

Edwin Edwards

Middle School by Bo Burnham

How to Disable Disqus Ads on your Blog

Derivation of Reservoir Sampling