On 7/17/06, Ryan Dillinger <[EMAIL PROTECTED]> wrote:

Now I believe I understand it up until the the last part \1.

/([a-zA-z]{3})\s*\1/

That's a backreference; it matches if the corresponding part of the
string is equal to what's in memory one at the time of the match.
Memory one holds the part of the string matched by the part of the
pattern inside the first pair of parentheses; in this case, that's the
string of exactly three letters that matched earlier. This pattern
will match strings like these:

 Paris in the the Spring.
 barbarian
 instantaneous
 somewhat hated
 microphone one

There's some confusion about what \1 and $1 mean, since they seem to
be two different names for the same string. Actually they're two very
different things: $1 is a (read-only) variable, holding a string from
a previous, completed, pattern match. But \1 is referring back to the
memory created in the current pattern match, which hasn't yet
completed. (You didn't ask, but that's why backreferences should be
found only in patterns, such as on the "pattern side" of the s///
command; on the "string side", since the pattern match is completed,
\1 isn't correct.)

You can find more about backreferences in the regular expression
manpages, such as perlre and perlrequick.

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to