Mr. Grummel Get the app
← All notes
LEARNING 5 MIN READ DRAFT — APRIL 2028

The pattern language that can check whether text is valid in one line, and take forever to explain why

Regular expressions let one compact line match or validate text that would take many lines of ordinary code, and that same compactness is exactly why they're notoriously hard to read back afterward.

Regular expressions describe a pattern of text using a compact, specialised syntax, letting a single short expression match, search for, or validate text that would otherwise take many lines of ordinary code to check by hand. That same compactness is exactly why a regular expression that works correctly can still be genuinely difficult for anyone else, including its own original author looking back at it later, to actually read and confidently understand.

A small set of special characters combines to describe increasingly complex patterns

Regular expressions are built from a small, fixed set of special characters, wildcards, repetition markers, character classes, that combine together to describe patterns of steadily increasing complexity, checking whether text matches an email address format, finding every instance of a pattern within a larger document, or splitting text apart at a specific delimiter. That small vocabulary is exactly what lets a genuinely complex matching rule get expressed in a single short line, instead of many lines of manually written comparison logic.

That same compactness makes regular expressions notoriously easy to get subtly wrong

Because a regular expression packs a large amount of matching logic into very few characters, a genuinely correct one can still be extremely difficult for a human to read back and verify at a glance, which is exactly why complex, business-critical regular expressions are a well documented source of hard-to-catch bugs, a subtly wrong pattern can look entirely correct on casual inspection while actually matching, or failing to match, cases its author never actually intended it to.

Regular expressions describe a pattern of text using a compact, specialised syntax, letting a single short expression match, search for or validate text that would otherwise take many lines of ordinary code to check, and that same compactness is exactly why a regular expression that works correctly can still be genuinely difficult for anyone else, including its own original author later, to read and understand.

What we're still unsure about

That regular expressions trade compactness for readability is well established, widely acknowledged practical experience among working programmers. What's more genuinely a formal, provable limitation is that some categories of text-matching problem, correctly parsing nested structures like properly matched brackets, are formally impossible for regular expressions to handle correctly no matter how cleverly they're written, since regular expressions are fundamentally limited to patterns definable by finite automata, and recognising in advance whether a specific text-matching problem actually needs a more powerful parsing tool instead of a regular expression is a genuine skill many programmers only really learn after running directly into the limitation themselves.

This sits inside Regular Expressions, one of eight topics in Programming, one of seven domains in Computer Science, one of seventeen subjects the app can quiz you on.

Draft — not published yet.
Try the pop quiz