I need to capture string between quote chars (") to change quotes for fancy ones, thus i created substitution, my code:
my $pk = qq|IV Baltic Sea NGO Forum "Challenges for Baltic Sea civil society"|;
$pk =~ s/"(\p{Word}+.?+)"/«$1»/g;
say $pk;
I meant regex as that:
- quoting char
- followed by at least one word char
- followed by any char
- until next quoting char (non-greedy capture)
I don’t get captured when there is any non-word char between quotes. Why?
I found another solution too, but i’d like to understand, why my regex does not work?
.?+is not reluctant quantifier. It is in fact a possessive? quantifier.You need to use
.+?instead.So, try this:
or, you can even use
[^"]+instead ofreluctant quantifier. It will automatically stop at the first"character: