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:
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.
|
|---|
| 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 | |
by ikegami (Patriarch) on Jan 08, 2009 at 02:14 UTC |