Mike
Mike

Reputation: 2391

Regex to find a repeated sentence in Notepad++

I need to find if the following words come more than one time in the document through Notepad++ regex search:

/resources/common.js

Given that these words could come between other words, like:

<script src="/resources/common.js" type="text/javascript"></script>

So the search shows the results just if these words "/resources/common.js" are present more than one time in that file.

I need this to find in a large folder with thousands of files, just to know which files have the repeated sentence.

Upvotes: 0

Views: 1566

Answers (2)

Lars Fischer
Lars Fischer

Reputation: 10149

You write about the regex, so I assume that you have access to the Unix tool-chain. Then you could use grep. The option -c reports the count:

grep -c cout *.cpp
bitset.cpp:1
Classes.cpp:2
ClearVectorOfUniquePtrs.cpp:2
COAP.cpp:2
ContainerCrash.cpp:0
CopyOptimisation.cpp:17

And another grep sorts out the zero and one matches:
grep -c cout *.cpp | grep -v -E ":0|:1$"

If you have Unix cut available this gives you the list of filenames:
grep -c cout *.cpp | grep -v -E ":0|:1$" | cut -d : -f 1

Replace cout with your string.

Upvotes: 0

SvenS
SvenS

Reputation: 795

Use the "Find in Files" tool (shortcut is Ctrl+Shift+F). Enter the search string (no regex), apply filters if desired, and choose the directory. Be sure that "In all sub-folders" is checked and hit "Find All", that should do the trick.

EDIT: You're actually looking for multi-line regular expressions, which are not supported by notepad++ and many other regex engines. See Multiline Regular Expression search and replace!

Upvotes: 1

Related Questions