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

you don't need to confuse people with the extra syntax of look-ahead/behind....you just need to match exactly what you want "a non-percent sign character followed by a percent sign character followed by q", i.e. $str =~ s/[^%]%q//g;

Replies are listed 'Best First'.
Re: Re: Re: regex match question
by leriksen (Curate) on Aug 04, 2003 at 06:07 UTC
    That doesn't work if %q starts the line - try
    /^%q|[^%]%q/

    or use the negative look behind
    /(?<!%)%q/
Re: Re: Re: regex match question
by graff (Chancellor) on Aug 05, 2003 at 03:49 UTC
    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.