in reply to Matching quote characters?
Actually it doesn't. Your non-greedy .*? matches as few characters as possible: Zero. Then, one or zero " follows. You can see it from the following snippet:But the .*? always gobbles up the trailing "my $string = '"foo"'; $string =~ s/\"(.*?)\"?/$1/; print $string;
For a solution to your problem, see the other posts.my $string = '"foo"'; $string =~ s/"(.*?)"?/_$1_/; # note that you don't have to escape " print $string; # prints __foo"
|
|---|