in reply to Re: Substitution backreference woes
in thread Substitution backreference woes

Forgive me, but the working examples do not seem to cover the use of \1 (etc) in the replacement expression.

Replies are listed 'Best First'.
Re^3: Substitution backreference woes
by Anonymous Monk on Jan 24, 2015 at 15:30 UTC
    Forgive me, but the working examples do not seem to cover the use of \1 (etc) in the replacement expression.
    It's covered in perlop
    Unlike sed, we use the \<digit> form in only the left hand side. Anywhere else it's $<digit>.
    Perl warns about it, too:
    $ perl -wE '$_ = "foo"; s/(foo)/bar \1/; say' \1 better written as $1 at -e line 1. bar foo
    We're told that backreference patterns can be used in the substitution by specifying \1, \2 (etc), but it doesn't seem to work.
    Who told you that?