Find results, multiple matches per line -> would like non-duplicate line result highlighting every match
-
(disclaimer - A quick search proves that this has been requested many times)
The feature I would like to see is a checkbox that allows the search to toggle between the way it works currently, and to show each line just once with all matches highlighted (which should be the default).
Unless there is something better, I am aware of two workarounds that almost work:
-
Use a regex search [link]
** This option (which I use) has two problems, (1) I have to look it up everytime I use it (2) it only highlights a single occurance of the matched text per line -
Copy the contents of the result pane and paste it into a new document and filter through it. [link]
** This option is kinda nuts, not only is it complex, but you lose the ability to click the matched line to go to the match line … also, highlighting all matches per line is still an issue
I’ve been a long time user of Notepad++ and know that there are frequent update to it. Since there is ongoing development, is there a reason that this feature has not been addressed? I ask this thinking that maybe I am just missing something, that there is already a way to do a “Find All in All Open Documents” and get a result panel without duplicate lines, with each match highlighted, and still have the ability to click matching lines and go to the matching line.
-
-
Hello, @michael-moynihan, and All
I’m the author of the second work-around mentioned and I must admit that my solution is not very practical ;-)) Unfortunately, I’ve never heard, up to now, of a setting, which would display each line once only, with all the matched occurrences highlighted. And I do agree that it would be a nice enhancement of the Find result panel ;-))
In the meanwhile, here are some other regexes ( Yes, again ! ), which you probably find easier to use !
The generic regex
(?-is)(
<Expression>)(.*(?1))?
, where <Expression> means, either, a character, a string, a word, a sentence or… a regex, matches, either :-
The area between the first <Expression> and the last <Expression> of each line scanned
-
The single <Expression> area of each line scanned
So :
- Open the Find dialog
Type in the regex above, in the Find what: zone, after replacing the part <Expression> by its true value
-
Select the
Wrap around
option and theRegular expression
search mode -
Click on the
Find All in Current Document
OR on theFind All in All Opened Documents
For instance, assuming the sample text, of 8 lines, below, taken from the license.txt file :
The License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you".
The regex
(?-is)(the)(.*(?1))?
matches between the first stringthe
and the last stringthe
of a line, with that exact case. Hence, the results :Search "(?-is)(the)(.*(?1))?" (6 hits in 1 file) new 1 (6 hits) Line 1: The License applies to any program or other work which contains a notice Line 2: placed by the copyright holder saying it may be distributed under the terms of Line 4: work, and a "work based on the Program" means either the Program or any derivative Line 5: work under copyright law: that is to say, a work containing the Program or a Line 6: portion of it, either verbatim or with modifications and/or translated into Line 7: another language. (Hereinafter, translation is included without limitation in the
The regex
(?i-s)(the)(.*(?1))?
matches between the first stringthe
and the last stringthe
of a line, whatever its case. Hence, the results :Search "(?i-s)(the)(.*(?1))?" (7 hits in 1 file) new 1 (7 hits) Line 1: The License applies to any program or other work which contains a notice Line 2: placed by the copyright holder saying it may be distributed under the terms of Line 3: this General Public License. The "Program", below, refers to any such program or Line 4: work, and a "work based on the Program" means either the Program or any derivative Line 5: work under copyright law: that is to say, a work containing the Program or a Line 6: portion of it, either verbatim or with modifications and/or translated into Line 7: another language. (Hereinafter, translation is included without limitation in the
The regex
(?-is)(\bthe\b)(.*(?1))?
matches between the first wordthe
and the last wordthe
of a line, with that exact case. Hence, the results :Search "(?-is)(\bthe\b)(.*(?1))?" (4 hits in 1 file) new 1 (4 hits) Line 2: placed by the copyright holder saying it may be distributed under the terms of Line 4: work, and a "work based on the Program" means either the Program or any derivative Line 5: work under copyright law: that is to say, a work containing the Program or a Line 7: another language. (Hereinafter, translation is included without limitation in the
The regex
(?i-s)(\bthe\b)(.*(?1))?
matches between the first wordthe
and the last wordthe
of a line, whatever its case. Hence, the results :Search "(?i-s)(\bthe\b)(.*(?1))?" (6 hits in 1 file) new 1 (6 hits) Line 1: The License applies to any program or other work which contains a notice Line 2: placed by the copyright holder saying it may be distributed under the terms of Line 3: this General Public License. The "Program", below, refers to any such program or Line 4: work, and a "work based on the Program" means either the Program or any derivative Line 5: work under copyright law: that is to say, a work containing the Program or a Line 7: another language. (Hereinafter, translation is included without limitation in the~~~
The regexes
(?-s)(\.)(.*(?1))?
OR(?-s)(\Q.\E)(.*(?1))?
match between the first period.
and the last period.
of a line… Hence, the results :Search "(?-s)(\.)(.*(?1))?" (4 hits in 1 file) new 1 (4 hits) Line 3: this General Public License. The "Program", below, refers to any such program or Line 7: another language. (Hereinafter, translation is included without limitation in the Line 8: term "modification".) Each licensee is addressed as "you".
The regex
(?i-s)(th\w*)(.*(?1))?
matches between the first stringth
, possibly followed with some word characters and the last stringth
of a line, possibly followed with some word characters, whatever its case. Hence, the results :Search "(?i-s)(th\w*)(.*(?1))?" (7 hits in 1 file) new 1 (7 hits) Line 1: The License applies to any program or other work which contains a notice Line 2: placed by the copyright holder saying it may be distributed under the terms of Line 3: this General Public License. The "Program", below, refers to any such program or Line 4: work, and a "work based on the Program" means either the Program or any derivative Line 5: work under copyright law: that is to say, a work containing the Program or a Line 6: portion of it, either verbatim or with modifications and/or translated into Line 7: another language. (Hereinafter, translation is included without limitation in the
Notes :
-
Take care to insert the two
\b
assertions, or the\Q
-\E
escape sequences INSIDE the parentheses, defining the group1
-
Note that the
(?1)
structure is a subroutine, which refers to the exact regular expression, contained in group1
, unlike the\1
syntax, which refers to the present value of the group1
!
Note, also that :
-
The regex
(?-is)^.*?\K<Expression>
would match, only, the first occurrence of <Expression>, of each line scanned -
The regex
(?-is)^.*\K<Expression>
would match, only, the last occurrence of <Expression>, of each line scanned
Best Regards,
guy038
P.S. :
I’ve just realized that a better syntax, for the generic regex, above, could be :
(?-is)(
<Expression>)(?:.*(?1))?
-
-
Thanks for the response. I’ve used the regex method, and yes, I read through your post and tried all the examples to see how they differ. The complexity between them, along with the results displayed for each is a bit challenging. I don’t say this meaning I don’t understand it, it’s just a lot of jumping through hoops.
I was hoping to see a few “me too”, “/agree” posts or better yet a “this feature is being considered” post. As it stands, I am afraid that your post will kinda bury most users and intimidate as it’s rather long. Not saying anything bad about your work-a-round as I have used it also.
Here is my use case:
- I have a handful of scripts or xml files open in Notepad++ and I’m doing a search for a keyword
- In the lines the keyword appears, it often appears more than once
- I am doing a “Find All in All Open Documents”
- While the results panel works, it would be a lot clearer if each line appeared just once, with the matching elements highlighted.
The feature I would like to see is a checkbox that allows the search to toggle between the way it works currently, and to show each line just once with all matches highlighted (which should be the default).
I think this would be a nice core feature add for Notepad++. If I am posting this in the wrong place, I can repost somewhere else.
-
Things often change slowly-to-never in Notepad++ feature land. Just seems to be the way it is…
Maybe (and this is just a guess) the reason it works as it does is because it is possible to write search expressions that would result in hits that “run together”. Thus the yellow highlighting would not clearly show where one hit ended and the next began if it was output together on one line in the Find result panel. Having one hit per output line avoids this potential problem.
Your best option is to make a feature request or a change-in-functionality request here: https://github.com/notepad-plus-plus/notepad-plus-plus/issues/ by opening a “New issue”. However, please spend a little time searching to see if your specific request already exists, in which case you can “up-vote” that Open Issue so that in theory it gets more attention. You may also add to an already-open Issue any new information you think relevant.
It’s definitely possible to “roll your own” solution to this, either by writing a plugin, or doing some scripting. Not what you want to hear, I’m sure, but it avoids the problem of waiting on someone else. Another approach would be modifying the source code yourself and submitting the change for adoption…
-
This is the first match I found:
issue #2481I found a handful of near matches. I would expect that there are more then just this one that address the find results panel.