Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a regular expression to find one of several words in Notepad++

I would like to use the "Find All in Current Document" button within Notepad++ to find all instances of a list of words. Is it possible to do this with a regular expression?

For example, if the list of words was

Foo,man,choo

and the file in notepad++ contained

01 The quick brown fox jumps over the lazy dog
02 The quick brown fox jumps over the lazy dog
03 The quick brown man jumps over the lazy dog
04 The quick brown fox jumps over the lazy dog
05 The quick brown fox jumps over the lazy dog
06 The quick brown foo jumps over the lazy dog
07 The quick brown fox jumps over the lazy dog
08 The quick brown fox jumps over the lazy dog
09 The quick brown choo jumps over the lazy dog
10 The quick brown fox jumps over the lazy dog

Lines 3,6 and 9 would be returned in the find results.

like image 277
Hoody Avatar asked Aug 07 '12 15:08

Hoody


People also ask

How do you search for a word in RegEx?

To run a “whole words only” search using a regular expression, simply place the word between two word boundaries, as we did with ‹ \bcat\b ›. The first ‹ \b › requires the ‹ c › to occur at the very start of the string, or after a nonword character.

Does Notepad support RegEx?

Using Regex to find and replace text in Notepad++ A quick cheat sheet for using Notepad++ to find and replace text in Notepad++. In all examples, use select Find and Replace (Ctrl + H) to replace all the matches with the desired string or (no string). And also ensure the 'Regular expression' radio button is set.


2 Answers

Notepad++ supports pipes operator | since 6.1.1 version.

You can use this regex for your search :

^.*(Foo|man|choo).*$
like image 143
zessx Avatar answered Oct 06 '22 03:10

zessx


If you want to just match these words then you can use

(foo|man|choo)

Result:

foo
man
choo

But if you want to match entire line which contains one of these words you could use

^.*(foo|man|choo).*$

Result:

03 The quick brown man jumps over the lazy dog
06 The quick brown foo jumps over the lazy dog
09 The quick brown choo jumps over the lazy dog
like image 39
Vaman Kulkarni Avatar answered Oct 06 '22 02:10

Vaman Kulkarni