Skip to content
Preptima
mediumConceptMidSeniorStaff

What is regular about a regular expression, and what does that word tell you your regex cannot do?

Regular expressions in the formal sense describe exactly the regular languages, the ones a finite automaton recognises with fixed memory, so they cannot match balanced parentheses or anything needing an unbounded count. Backreferences take practical regex past that class and cost the linear-time matching guarantee.

4 min readUpdated 2026-10-09

Answer

Short answer

"Regular" is a technical term. Formal regular expressions describe exactly the regular languages, which are the languages a finite automaton can recognise using a fixed number of states and no other memory. So a true one cannot match balanced parentheses, check that two counts are equal, or parse anything with unbounded nesting. The regex in your language may have features that go beyond that, and supporting them is why most engines backtrack, which is what makes some patterns exponentially slow.

Was this answer helpful?

Likely follow-ups

  • Why can a regex match parentheses nested at most three deep but not arbitrarily deep?
  • Your validation pattern has a nested quantifier and takes user input. How do you prove it is safe or replace it?
  • A lexer is built from regular expressions but the parser is not. What is each one responsible for?
  • What do you lose when you move a pattern from a backtracking engine to RE2, and how do you find out before deploying?

Related questions

Further reading