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