Matching Nested Structures With Regular Expressions in Python

Regular expressions cannot parse nested structures. Nested structures are not regular, by definition. They cannot be constructed by a regular grammar, and they cannot be parsed by a finite state automaton (a regular expression can be seen as a shorthand notation for an FSA).

Today’s “regex” engines sometimes support some limited “nesting” constructs, but from a technical standpoint, they shouldn’t be called “regular” anymore.

Leave a Comment