\1 is the same thing as $1 inside of a regex, but it is generally
recommended that you don't use it.
>From 'perldoc perlre':
" Warning on \1 vs $1
Some people get too used to writing things like:
$pattern =~ s/(\W)/\\\1/g;
This is grandfathered for the RHS of a substitute to avoid shocking
the
sed addicts, but it's a dirty habit to get into. That's because in
PerlThink, the righthand side of an "s///" is a double-quoted
string.
"\1" in the usual double-quoted string means a control-A. The
customary
Unix meaning of "\1" is kludged in for "s///". However, if you get
into
the habit of doing that, you get yourself into trouble if you then
add
an "/e" modifier.
s/(\d+)/ \1 + 1 /eg; # causes warning under -w
Or if you try to do
s/(\d+)/\1000/;
You can't disambiguate that by saying "\{1}000", whereas you can fix
it
with "${1}000". The operation of interpolation should not be
confused
with the operation of matching a backreference. Certainly they mean
two
different things on the *left* side of the "s///"."
-----Original Message-----
From: Ryan Dillinger [mailto:[EMAIL PROTECTED]
Sent: Monday, July 17, 2006 6:10 PM
To: [email protected]
Subject: pattern matching
Hello All,
I was studying some pattern matching. And I ran into this piece of code.
Now I believe I understand it up until the the last part \1.
Can someone explain it for me please?
Match lowercase a through z, uppercase A through lc z
no more than three times, with white space zero or one times
then I'm stumped, what's the 1 for?
/([a-zA-z]{3})\s*\1/
Thanks for the Help!
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>