Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple word search and replace in notepad++

Tags:

notepad++

Does anyone know how to replace several different words all at once in notepad++.

For example;

I have "good", "great" and "fine" and I want to replace them with "bad", "worse" and "not" all at once

I know that I can replace them one by one, but the problem I am facing requires that I replace a lot of words, which is not convenient to do.

like image 512
didiFaridi Avatar asked Jul 09 '12 05:07

didiFaridi


People also ask

How do you find and replace multiple words in Notepad?

Open Notepad++ and go to Search > Find in Files... or press CTRL+SHIFT+F. This opes the Find in Files menu. Under Find what:, enter the word or phrase that you need to change. Under Replace with:, enter the new word or phrase.

How do I change all occurrences of a word in Notepad?

CTRL+H to get to the Replace dialog (or Search ==> Replace via the menu). Input the string to find and input the string to replace it with and then hit the 'replace all' button on the right.


2 Answers

Try a regular expression replace of (good)|(great)|(fine) with (?1bad)(?2worse)(?3not).

The search looks for either of three alternatives separated by the |. Each alternative has ist own capture brackets. The replace uses the conditional form ?Ntrue-expression:false-expression where N is decimal digit, the clause checks whether capture expression N matches.

Tested in Notepad++ 6.3

Update:

You can find good documentation, about the new PRCE Regular Expressions, used by N++, since the 6.0 version, at the TWO addresses below :

http://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html

http://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html

The FIRST one concerns the syntax of regular expressions in SEARCH

The SECOND one concerns the syntax of regular expressions in REPLACEMENT

And, if you can understand "written French", I made a tutorial about PCRE regular expressions, stored in the personal site of Christian Cuvier (cchris), at the address below :

http://oedoc.free.fr/Regex/TutorielRegex.zip

(Extracted from a posting by THEVENOT Guy at http://sourceforge.net/p/notepad-plus/discussion/331754/thread/ca059a0a/ )

like image 148
AdrianHHH Avatar answered Sep 18 '22 22:09

AdrianHHH


Install Python Script plugin from Plugin Manager.

Create a file with your substitutions (e.g., C:/Temp/Substitutions.txt), separate values with space:

good bad great worse fine not 

Create a new script:

with open('C:/Temp/Substitutions.txt') as f:     for l in f:         s = l.split()         editor.replace(s[0], s[1]) 

Run the new script against the text you want to substitute.

like image 31
Mauricio Morales Avatar answered Sep 17 '22 22:09

Mauricio Morales