Can some explain to me why you can not use regex to describe a recursive structure.
Eg
- A = *A?B
Can some explain to me why you can not use regex to describe a recursive structure.
Eg
Because a regex (in the sense of regular languages, at least) corresponds to a finite state machine. You'd need an infinite number of states to track arbitrary levels of nesting.
Even though regular expressions cannot express recursion by formal definition, for some languages like Perl and Ruby there are 'regex' implementations that support recursion.
Also for python there is an alternative regex implementation supporting recursion that's not in the standard lib.
But again, regular languages don't have recursive structures, so formally regular expressions cannot express recursive structures by definition.