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:
s/ . (?<!J(?=AZZ)) (?<!JA(?=ZZ)) (?<!JAZ(?=Z)) (?<!JAZZ) /a/xgs;
s/~/a/g; s/JAZZ/~/g; s/[^~]/a/g; s/~/JAZZ/g;
s/(JAZZ|.)/$1 eq 'JAZZ' ? $1 : 'a'/egs;
s/(JAZZ)|./defined($1) ? $1 : 'a'/egs;
s/((?:JAZZ)*)./$1a/gs;
Update: Or more.
In reply to Re: A challenging problem in perl regular expression
by ikegami
in thread A challenging problem in perl regular expression
by yai
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |