ocs has asked for the wisdom of the Perl Monks concerning the following question:
Hello monks,
I got a small problem concerning references in perls regex flavor.
For example, I got a string like this
And I want to match all double characters (a-z), i.e. ll and rr in the given string and contract them to one char. (Please do not take this seriously, its just an example.)
So I went like this:
$lala =~ s/([a-z])$1/$1/gIt does not work. So I played around:
$lala =~ s/([a-z])\1/$1/gThis works. But what I kept in mind was this: Warning on \1 vs $1
So I don't know why in the first version the $1 in the matching part (not the substitute part) does not work but with \1 in the second version? I thought \1 is obsolete and just a relic of a sed styled referencing.
This is nothing big, but ... did I miss something?
Thanks in advance,
ocs.
tennis players have fuzzy balls.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: perl regex referencing
by zshzn (Hermit) on Sep 18, 2007 at 08:26 UTC | |
Re: perl regex referencing
by Prof Vince (Friar) on Sep 18, 2007 at 08:22 UTC | |
Re: perl regex referencing
by bruceb3 (Pilgrim) on Sep 18, 2007 at 08:18 UTC | |
Re: perl regex referencing
by ikegami (Patriarch) on Sep 18, 2007 at 14:38 UTC | |
Re: perl regex referencing
by eff_i_g (Curate) on Sep 18, 2007 at 14:16 UTC |