3

I use this regex in Notepad++, to search and replace multiple words.

(good)|(great)|(fine)

(?1bad)(?2worse)(?3not)

Problem is, it doesnt work in Powergrep, any way to alter it? Problem is, Notepad++ has limited lengh or regular expression, and Powergrep doesnt, and it also supports list of regular expressions.

logi-kal
  • 7,107
  • 6
  • 31
  • 43
Jim8645
  • 181
  • 3
  • 15
  • Is there some example that would work in one of those programs? – Jim8645 Jun 21 '16 at 14:30
  • If you read my question, I already have multiple replace regex in Notepad++, and I explained why I need it in Powergrep, replacing one by one would be pointless. It is not helpfull at all what you wrote. – Jim8645 Jun 22 '16 at 13:28

1 Answers1

2

In the PowerGREP manual the replacement with conditionals is never mentioned. I suggest you a generic way around, that solves N search & replace in just 3 steps overall (obviously, if you have only 3 words to replace you may do first replacing them one by one):

First step (adding markers)

(F_1)|(F_2)|(F_3)|...|(F_n)

{\1[R_1]}{\2[R_2]}{\3[R_3]}...{\n[R_n]}

Where (F_1, ..., F_n) are the words (or regular expressions) to replace with the terms (R_1, ..., R_n), respectively.

In your example:

(good)|(great)|(fine)

{\1[bad]}{\2[worse]}{\3[not]}

Second step (keeping good)

\{[^\[\]\{\}]+\[([^\[\]\{\}]*)\]\}

\1

Third step (deleting evil)

\{\[[^\[\]\{\}]*\]\}

null

If you are working with words that already include the use of curly and squared brakets and you don't want to make mistakes, you can use other markers (angular brackets, triple apexes, and so on and so forth).

logi-kal
  • 7,107
  • 6
  • 31
  • 43