in reply to Matching quote characters?

try
my $string = '"foo"'; my $string2 = '"foo'; $string =~ s/\"(.*?)\"|\"(.*?)/$1$2/; $string2 =~ s/\"(.*?)\"|\"(.*?)/$1$2/; print "$string -- $string2\n";
I think in the $string =~ s/\"(.*?)\"?/$1/; version both the .*? and the \"? are non-gready, so it's a question of which one is less gready competing, and \"? wins becuas it's non -greedy.

Updated:Corrected my muddle-headedness about "non-greedy ", thanks to betterwold.

Replies are listed 'Best First'.
Re^2: Matching quote characters?
by betterworld (Curate) on Aug 05, 2006 at 19:22 UTC
    I think in the $string =~ s/\"(.*?)\"?/$1/; version both the .*? and the \"? are non-gready
    No, \"? is greedy. \"?? would be non-greedy.