Search code examples
phpregexrecursionpcrebacktracking

"Backtracking over a recursion" in PCRE


https://www.regular-expressions.info/recursebacktrack.html

Section - "Palindromes of any length in Perl and Ruby"

http://prntscr.com/i06qas

"PCRE, however, does not backtrack into the third recursion. It does backtrack over the third recursion when it backtracks the first alternative in the second recursion."

What does "it does backtrack over the third recursion" mean? The "over" part...


Solution

  • Over means skip.

    In simple words it means PCRE won't return again into third recursion to try a zero-length match after backtracking into second side of alternative of third recursion. It exits as soon as second side of alternative is satisfied without being worry about ? quantifier that may lead into skipping a literal character match as well.