OCTweak has asked for the wisdom of the Perl Monks concerning the following question:
On the following code, could someone explain me, why in the first match, the \1 reference, did not block the double quote from being considered part of $2 ?
#!/usr/bin/perl use strict; use warnings; my $line; print "\n"; $line = '<a href="http://www.mysite.com/" target="_blank">'; $line =~ /\shref=(["'])?([^\s\>\1]+)/; # FIRT MATCH if (defined $1) {print "\$1= $1\n";} else {print "1) not defined\n";} if (defined $2) {print "\$2= $2\n";} else {print "2) not defined\n";} print "\n"; $line =~ /\shref=(["'])?([^\s\>"']+)/; # SECOND MATCH if (defined $1) {print "\$1= $1\n";} else {print "1) not defined\n";} if (defined $2) {print "\$2= $2\n";} else {print "2) not defined\n";}
==Program Output
$1= "
$2= http://www.mysite.com/"
$1= "
$2= http://www.mysite.com/
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Backreferences
by Abigail-II (Bishop) on Jul 23, 2003 at 15:00 UTC | |
|
Re: Backreferences
by snax (Hermit) on Jul 23, 2003 at 15:07 UTC | |
by Thelonius (Priest) on Jul 23, 2003 at 15:38 UTC | |
|
Re: Backreferences
by artist (Parson) on Jul 23, 2003 at 15:06 UTC | |
|
Re: Backreferences
by Anonymous Monk on Jan 06, 2018 at 07:02 UTC | |
by karlgoethebier (Abbot) on Jan 06, 2018 at 19:34 UTC | |
by soonix (Chancellor) on Jan 07, 2018 at 11:57 UTC | |
by karlgoethebier (Abbot) on Jan 07, 2018 at 12:17 UTC |