Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
It looks like the first (.)\2 would match ab, but the next (.)\1 would only match bb? I know I'm reading it incorrectly just begging for a plain explanation of whats going on there. Thanks!$_ = "yabba dabba doo"; if (/y(.)(.)\2\1/) { # matches 'abba' print "It matched a after the y"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex from Learning Perl
by CountZero (Bishop) on Feb 17, 2012 at 20:17 UTC | |
CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James My blog: Imperial Deltronics | [reply] [d/l] [select] |
by rayh (Initiate) on Feb 17, 2012 at 20:21 UTC | |
| [reply] |
|
Re: Regex from Learning Perl
by toolic (Bishop) on Feb 17, 2012 at 20:21 UTC | |
| [reply] [d/l] [select] |
|
Re: Regex from Learning Perl
by Anonymous Monk on Feb 17, 2012 at 20:21 UTC | |
First (.) matches "a" and stores it in $1 Second (.) matches "b" and stores it in $2 \2 matches the value of $2 , it matches "b" \1 matches the value of $1 , it matches "a" use re 'debug';
| [reply] [d/l] [select] |
by Anonymous Monk on Feb 17, 2012 at 20:28 UTC | |
| [reply] [d/l] |