Re: [pcre-dev] Forward back references

Página superior
Eliminar este mensaje
Autor: Philip Hazel
Fecha:  
A: Juergen Leising
Cc: pcre-dev
Asunto: Re: [pcre-dev] Forward back references
On Tue, 11 Dec 2007, Juergen Leising wrote:

> I have difficulties with forward back references. For example:
>
>    /^abc(d)\1$/ 
> versus 
>    /^abc\1(d)$/

>
> Shouldn't abcdd match with both patterns?


No. Try it with perl - it's the same.

> With the first one (actual back reference) it does.
> But not with the second one (forward back reference):


The second can't - it hasn't matched the parentheses, so how can it back
reference them? Forward backreferences make sense only inside loops,
when the parentheses have matched on a previous iteration of the loop.

Note: a backreference is *not* a "subroutine call". PCRE (and Perl 5.10)
do have "subroutine calls". Try

/^abc(?1)(d)/

Grep for "subroutine" in 'man pcrepattern'.

Philip

--
Philip Hazel