in reply to A challenging problem in perl regular expression

What makes it hard to do in a regexp is that "JAZJ" is not "JAZZ", yet you don't want to replace it. This is not the job of a regexp.

Two ways:

Update: Or more.

Replies are listed 'Best First'.
Re^2: A challenging problem in perl regular expression
by yai (Initiate) on Jan 08, 2009 at 02:05 UTC
    ikegami, thanks a lot. but the last one doesn't work if there is more than 1 'JAZZ' in a string. I tried on "JAZZxxxxJAZZ" but the result was "JAZZaaaaaaaa".

      It does work if there's more than one 'JAZZ' in the string, but it doesn't work if there's one at the end of the string. Scratch that one.

      The best test case is probably "JAZZxxJAZZJAZZxxJAZJAZZxxJAZZ"