Find and Replace Multiple different words with the same word in a text file


If you have a use-case where you want to replace multiple words example Word-A, Word-B, and Word-C by Word, you can do that using a Text Editor that supports regular expressions in Find and Replace future, a few of such tools are Notepad++ for Windows or Sublime Text that you can use on both Windows and macOS,

How to Find and Replace Multiple words with the same word in a text file?

  1. Open the file in Notepad++/Sublime text,
  2. Open Find and Replace,
  3. Make sure regular expression option is enabled,
  4. Find: (WordA|WordB|WordC)
  5. Replace With: Word
  6. Click on Replace All
Example: File content before:
Lorem ipsum WordA dolor sit amet,
onsectetur adipiscing elit. Maecenas suscipit justo dapibus 
faucibus pharetra. Proin egestas leo non augue scelerisque, 
a aliquet odio efficitur. Aenean vel purus sed odio tempus 
rutrum. Phasellus vel WordB odio orci. 
Vestibulum ante ipsum primis in faucibus orci luctus et 
ultrices posuere cubilia curae; Sed venenatis tristique 
ex eu tincidunt. Morbi at lorem fermentum, sollicitudin 
arcu id, malesuada mauris. Fusce malesuada odio sed 
pellentesque dapibus. WordC Nam viverra 
nisl sed elit pulvinar pretium. In pharetra purus vitae 
ligula pretium WordA porta. Curabitur eu 
eros at quam porta condimentum in in massa. Fusce nec 
arcu nisl. Pellentesque molestie sapien in augue dapibus, 
sed consectetur elit WordA faucibus. 
Quisque id urna eget ipsum vestibulum feugiat id at mi WordC.
File content After change:
Lorem ipsum Word dolor sit amet,
onsectetur adipiscing elit. Maecenas suscipit justo dapibus 
faucibus pharetra. Proin egestas leo non augue scelerisque, 
a aliquet odio efficitur. Aenean vel purus sed odio tempus 
rutrum. Phasellus vel Word odio orci. 
Vestibulum ante ipsum primis in faucibus orci luctus et 
ultrices posuere cubilia curae; Sed venenatis tristique 
ex eu tincidunt. Morbi at lorem fermentum, sollicitudin 
arcu id, malesuada mauris. Fusce malesuada odio sed 
pellentesque dapibus. Word Nam viverra 
nisl sed elit pulvinar pretium. In pharetra purus vitae 
ligula pretium Word porta. Curabitur eu 
eros at quam porta condimentum in in massa. Fusce nec 
arcu nisl. Pellentesque molestie sapien in augue dapibus, 
sed consectetur elit Word faucibus. 
Quisque id urna eget ipsum vestibulum feugiat id at mi Word.
Notepad++ Unsaved file backup location
Notepad++ Unsaved file backup location





      Topics: Pages | 2015 | Tutorials | Questions | Python