0

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.

Mike
  • 2,051
  • 4
  • 28
  • 46
  • Sorry, I don't understand your request. If you enter "/resources/common.js" in your Find tool, choose Search Mode "Normal" and click on "Find all in current document", you will get all occurrences of this string (regardless of preceding and trailing characters). – SvenS Oct 19 '12 at 11:36
  • ya, but I need to find it in a big folder with thousands of files, just to know which ones have the repeated sentence. – Mike Oct 19 '12 at 11:38
  • Or are you trying to find only lines with nothing in them but your search string? – SvenS Oct 19 '12 at 11:38
  • no they could have words before and after like the example after the line "Given that" – Mike Oct 19 '12 at 11:39

2 Answers2

1

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!

Community
  • 1
  • 1
SvenS
  • 795
  • 7
  • 15
  • I need the regex command to use it with other programs after that to edit the results – Mike Oct 19 '12 at 11:41
  • well, you don't need to use a regex, because you look for a simple string. (In other words the regex is trivial, consisting of nothing but the string you're looking for). I can only guess what it is you're looking for now, but this will find the whole line that contains the search string: .*/resources/common\.js.* Is that what you needed? – SvenS Oct 19 '12 at 11:45
  • no problem if it finds the whole, as long as the string is repeated – Mike Oct 19 '12 at 11:46
  • ah, okay, I think I get it: You need a *multi-line* regex that matches only in files that contain your string more than once. Is that it? – SvenS Oct 19 '12 at 11:49
  • ya, finds the string if it shows more than one time in the file, and ignores if it just one time – Mike Oct 19 '12 at 11:51
  • I'm sorry to have to inform you that Notepad doesn't support multiline regexes. See this question for reference: http://stackoverflow.com/questions/1441044/multiline-regular-expression-search-and-replace – SvenS Oct 19 '12 at 11:54
  • why this regex that I need should be multi-line? – Mike Oct 19 '12 at 11:56
  • because you want to find occurrences of the string in multiple lines of one file – SvenS Oct 19 '12 at 11:59
  • I think it should be something like: find this "/resources/common.js" if it is more than once in the file.. I don't think it should have anything with multiple lines.. – Mike Oct 19 '12 at 12:02
  • right, it would help you if you could tell notepad++ to ignore any files that have less than 2 hits, but I didn't find that feature. Then you could use the "Find in Files" feature, yet again without regex – SvenS Oct 19 '12 at 12:02
  • ok, what is the suggested multi-line regex you are thinking of? I'll try to use EditPad if I couldn't use NP++ – Mike Oct 19 '12 at 12:04
  • That depends on what engine EditPad uses. You could try "/resources/common\.js.*/resources/common.js", but perhaps you should open a new question for that. – SvenS Oct 19 '12 at 13:18
0

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.

Lars Fischer
  • 9,135
  • 3
  • 26
  • 35