in reply to Re: Re: regex match question
in thread regex match question

In addition to the problem leriksen pointed out, your suggestion deletes an extra character. In order to meet the OP's spec, it gets a bit uglier:
$str =~ s/^%q|([^%])%q/$1/g;
Basically, it would be less confusing to learn about zero-width assertions.

Granted, it does pose a bit of a challenge to "learn" the various zero-width and non-grouping forms. I haven't memorized them yet myself -- I just scan through the "perlre" man page every time I need to use one of those "(?whatever)" thingies. I actually don't mind that. I'm used to it from always having to do the same thing for a dozen different common C library calls -- I still do that, after "knowing" C for 15 years.