mrabarnett/mrab-regex

Recursive patterns

mrabarnett opened this issue · 2 comments

Original report by Anonymous.


In order to parse certain strings belonging to certain kinds of languages, recursive patterns for recursive matching are necessary. For example, if you want to parse and capture a parenthesized chunk of text which may contain nested parenthesis, you'll need to have recursion.

Perl already supports recursive matching, so does PCRE and with that many libraries for languages such as PHP. I always wondered why the Python regex engines never did.

Please refer to http://perldoc.perl.org/perlre.html for documentation on the widely accepted syntax for recursive patterns.

Original comment by Anonymous.


Please could you provide a set of tests, checking what the groups should match, including the expected results of the matched.captures() method. Try to make them short but thorough.

Note that Perl allows backtracking into the recursive part, whereas PCRE doesn't (it treats the recursive part as atomic).

I'm aiming for the Perl behaviour.

Original comment by Anonymous.


Added in regex 0.1.20120103.