Hi,
I thought I understood Perl RE to a reasonable extent, but this is puzzling me:
#!/usr/bin/perl
use strict;
use warnings;
my $test = "'some random string'";
if($test =~ /\'?(.*?)\'?/) {
print "Captured $1\n";
print "Matched $&";
}
else {
print "What?!!";
}
prints
Captured
Matched '
It seems it has matched the ending ' alone, and so captured nothing.
I would have expected it to match the entire thing, or if it's totally non-greedy, nothing at all (as everything there is an optional match).
This in between behaviour baffles me, can anyone explain what is happening?
Thanks,
Sundar.