Autor: Philip Hazel Fecha: A: Matthias B. Cc: pcre-dev Asunto: Re: [pcre-dev] PCRE and recursion feature - (?R) - doesn't work as
expected
On Fri, 10 Jul 2009, Matthias B. wrote:
> I've read about the recursion feature in pcre.txt. I also tried it with
> simple expressions like "\w(?R)" - shouldn't that match the same like
> "\w\w"?
No.
>It doesn't and I don't understand why. Can you mention that to me?
A usable recursive regex, like a recursive function in a programming
language, must have some way of stopping the recursion. Your pattern
goes on for ever. It matches an infinite number of \w (which is of
course impossible). A slightly different pattern:
\w($|(?R))
is the same as
\w+
Notice the option for stopping when the end of the text is reached.