How to highlight repeated words (multiple words repeated), in a Text file?
-
Problem: Example of Text file
1. abc 2. bcd 3. abc 4. aeef 5. bcd 6. fgh
I want abc repeated in line 1.and 3. & bcd repeated in line 2. and 5. to be highlighted
highlighted Or marked with Different colour for each word… or same colour
1st priority is to mark repeated words
I dont know which words are repeated…
I guess there may be 50 some different words…
with each word repeated about 5 times… -
@Ki-An ,
marked with Different colour for each word
Notepad++ doesn’t have that many highlight colors.
If you select the whole word
abc
then right click and choose Style All Occurrences of Token > Using ##th Style, then you can get some of what you want, but there’s only 5 styles to choose from.I showed making
abc
one style andbcd
a different style. But you cannot get 50 different colors.Please note that Settings > Preferences > Highlighting may affect whether you can style just whole words or whether it can be partial words or go across a word boundary, and the usermanual section on that page of settings describes what each of the settings mean. (Oh, a note: the manual hasn’t been updated yet: that setting box was renamed from “Mark All” to “Style All Occurrences of Token” in a version after v8.0; I need to check on that)
Also, please understand that such styling is temporary, and is not saved anywhere in the file or in Notepad++ config files – so the next time you run Notepad++, those stylings will not be there. The Style … Token colors are just meant as a temporary highlight, not as something persistent or that can be distributed to others.
-
@PeterJones Wow, quick reply…Thankyou…
but still have a problem…
its ok, if there isnt many different colour, and colouring is temporary…
my priority is to colour them… even single colour
but point is I dont know which words are repeated
right click and style words, requires me to select word
which I dont know!?
any way to automatically recognize repeated words, and highlight them -
@Ki-An ,
If you did something like Search > Mark, with “Bookmark Line” checked and “Search Mode = Regular Expression”, and searched for
(\b\w+\b)(?=(?s).*\1)
What it’s doing is searching for any group of 2 or more word characters (letters, numbers, and underscore) with word boundaries around it (which is how I define a “word”), followed by anything followed by another instance of the same word. It will mark/highlight the first instance of each of those words, and also add the circle bookmark to the left.
After these are marked, you can then use Search > Bookmark > Next/Previous Bookmark menu entries (or their keyboard shortcuts) to easily navigate between the
matchesbookmarked lines (that, the lines that contain matches). Once you are navigating, you could use the style-all-occurrences if you want to see all of that particular word or not (or just use the smart-highlighting which happens when you manually select the word) -
@PeterJones said in How to highlight repeated words (multiple words repeated), in a Text file?:
Wow Great, highlight with Navigation too…
saved a lot of time… Thanks a-lot