multiple search and remove
-
@peterjones Thanks,
I should’ve not mentioned files it made this a little bit confusing (I have only file),
alright I will point this in a more simpler way
example text (orignal)
cup trophy mug cupboard
I am looking to delete multiple words from the text without having to find and replace every time example: I am looking to delete word ( mug, and cupboard ) to get the outcome:
cup trophy
instead of doing simple find and replace with nothing for each word, I am looking to do it all at once
look up for every ( mug, and cupboard ) at the same time replace with nothingI think there might be some regex codes to do this but in my case my actual lines are much longer than the example above (with over 30 character per line which I think notepad++ wouldn’t fit in the find/search box )
-
I still don’t think you’re formulating your question and data well yet, but let’s press on. Also, please don’t change your data right in the middle of trying to ask your question.
But…ok…for your
cup
,trophy
data…find what:
^(mug|cupboard)\R
replace with: make sure this box is empty
mode: regular expressionwith over 30 character per line which I think notepad++ wouldn’t fit in the find/search box )
The length of data you can put in the find-what and replace-with boxes is actually quite long, 2046 characters I think, so you have some room to work.
-
This post is deleted! -
@alan-kilborn Thanks
that’s my point but the difference in here that is my original text has a quiet high number of characters
original sample:
MTkxMTMxOTkyMzcxNzg5ODcy.B3G_W0.pOFRk4TGe_SPNUhKrb58IVJvty6 ODY5NjU0MDYwNzkyOTM5NTEw.XqCHPX.bNW7X8fayguYEnVBmRkMvejlG4s MjY4MzU4MjQwMTMyMTE3ODky.HlytHz.JOehsSFExPn1T_7RkoQq8LrZwjK NDY4MTMxOTg5NjE2NjI1NjUz.ZvEGgz.3tHiZ80sc64WyQV5fr-Fklhax_O NjUwNzM1Mzc3MzA0MDk1OTgd.Pr75Ph.JtTLUwxZWHaqc5jmvoueS0h6KGY MTgzNTY4ODkyODAxMDMwOTE5.FKIb9Z.41SZmRhuPVXYAtienEsH2pG6075 MjQ5NDI5MzgzMzQ3MTUzMDE2.G2uVES.-8pra1RI5TPOtMo0BDlQekL4mnx NzIxNDY0ODA2ODgwNzU3Mzkz.AAoT1D.AGLYSncFvm8iKBlQuXfabRVprZ- ODgyNjU1NzQ4OTg0OTk2NDYz.LO9ibu.HnBjcEiobV3QLWlKDdvPxOrZpIR OTYwMTY3NjQyMzkzMzE0NDM0.TJPWbq.Pfca28AZmxeM-uqEVi6j1HkFn_K
fitting 100+ of these characters is a bit high for a 2046 box, is there any other way to achieve this?
thank you
-
Hello, @handa-flocka, and All,
Well, @handa-flocka, you gave us an original sample of your file :
MTkxMTMxOTkyMzcxNzg5ODcy.B3G_W0.pOFRk4TGe_SPNUhKrb58IVJvty6 ODY5NjU0MDYwNzkyOTM5NTEw.XqCHPX.bNW7X8fayguYEnVBmRkMvejlG4s MjY4MzU4MjQwMTMyMTE3ODky.HlytHz.JOehsSFExPn1T_7RkoQq8LrZwjK NDY4MTMxOTg5NjE2NjI1NjUz.ZvEGgz.3tHiZ80sc64WyQV5fr-Fklhax_O NjUwNzM1Mzc3MzA0MDk1OTgd.Pr75Ph.JtTLUwxZWHaqc5jmvoueS0h6KGY MTgzNTY4ODkyODAxMDMwOTE5.FKIb9Z.41SZmRhuPVXYAtienEsH2pG6075 MjQ5NDI5MzgzMzQ3MTUzMDE2.G2uVES.-8pra1RI5TPOtMo0BDlQekL4mnx NzIxNDY0ODA2ODgwNzU3Mzkz.AAoT1D.AGLYSncFvm8iKBlQuXfabRVprZ- ODgyNjU1NzQ4OTg0OTk2NDYz.LO9ibu.HnBjcEiobV3QLWlKDdvPxOrZpIR OTYwMTY3NjQyMzkzMzE0NDM0.TJPWbq.Pfca28AZmxeM-uqEVi6j1HkFn_K
OK ! Now, which characters or lines should be marked, deleted or replaced with other stuff, from your example ???
BR
guy038
-
@guy038 hello
will go with the first 6 lines from the file above (original) “find and delete.”
1-MTkxMTMxOTkyMzcxNzg5ODcy.B3G_W0.pOFRk4TGe_SPNUhKrb58IVJvty6 2-ODY5NjU0MDYwNzkyOTM5NTEw.XqCHPX.bNW7X8fayguYEnVBmRkMvejlG4s 3-MjY4MzU4MjQwMTMyMTE3ODky.HlytHz.JOehsSFExPn1T_7RkoQq8LrZwjK 4-NDY4MTMxOTg5NjE2NjI1NjUz.ZvEGgz.3tHiZ80sc64WyQV5fr-Fklhax_O 5-NjUwNzM1Mzc3MzA0MDk1OTgd.Pr75Ph.JtTLUwxZWHaqc5jmvoueS0h6KGY 6-MTgzNTY4ODkyODAxMDMwOTE5.FKIb9Z.41SZmRhuPVXYAtienEsH2pG6075 7-MjQ5NDI5MzgzMzQ3MTUzMDE2.G2uVES.-8pra1RI5TPOtMo0BDlQekL4mnx 8-NzIxNDY0ODA2ODgwNzU3Mzkz.AAoT1D.AGLYSncFvm8iKBlQuXfabRVprZ- 9-ODgyNjU1NzQ4OTg0OTk2NDYz.LO9ibu.HnBjcEiobV3QLWlKDdvPxOrZpIR 10-OTYwMTY3NjQyMzkzMzE0NDM0.TJPWbq.Pfca28AZmxeM-uqEVi6j1HkFn_K
the get the outcome
7-MjQ5NDI5MzgzMzQ3MTUzMDE2.G2uVES.-8pra1RI5TPOtMo0BDlQekL4mnx 8-NzIxNDY0ODA2ODgwNzU3Mzkz.AAoT1D.AGLYSncFvm8iKBlQuXfabRVprZ- 9-ODgyNjU1NzQ4OTg0OTk2NDYz.LO9ibu.HnBjcEiobV3QLWlKDdvPxOrZpIR 10-OTYwMTY3NjQyMzkzMzE0NDM0.TJPWbq.Pfca28AZmxeM-uqEVi6j1HkFn_K
now if I tried @Alan-Kilborn regex code it will actually work, but it wouldn’t fit notepad++ search/find box, and the actually number I am looking to delete in my file is more than 500+
i guess there might be some python code that somebody has already made or some feature in notepad++ that I am missing would do trick
thanks
-
@handa-flocka said in multiple search and remove:
fitting 100+ of these characters is a bit high for a 2046 box, is there any other way to achieve this?
You may be able to shrink it down… for example, if the six characters between the periods were unique, you might be able to do something like
^.*\.(B3G_W0|XqCHPX|HlytHz)\..*$(\R|\Z)
… but that’s not likely enough.At this point, a scripting solution is you best choice.
i guess there might be some python code that somebody has already made or some feature in notepad++ that I am missing would do trick
Oh, good, you’re willing to use pythonscript. I know that years ago, when we’d get questions like this, someone wrote a script that will look for all the lines in file2 and delete those lines from file1, but after 10 minutes of searching, I gave up and just wrote the slightly simpler script, where you manually populate the array in
list_of_strings
in the script, and then it will search for each of the texts in that array, and delete any lines in the active file that contain that string. If you want to also read all the lines from editor2 to populate thelist_of_strings
array, that’s simple enough to do, but I’ll leave it as an exercise to the reader; if you need help, show us what you tried, and we can point you in the right direction.# encoding=utf-8 """ in response to https://community.notepad-plus-plus.org/topic/22331/multiple-search-and-remove You can run this script, and it will delete all the lines in the active file that contain that text (even if it's as a substring). You can comment/uncomment lines in the script to make it match only whole lines (so the string "blah" would only match "blah", not "something blah something") You could modify it to read editor2 contents and then delete matching lines in editor1, but I will leave that as an exercise for the reader. Populate the list_of_strings array below, then run this script. The text in each line will be treated as a literal string, so regex characters will not be treated as regex (ie, dot will match a dot, not any single character). """ class forum_post22331: list_of_strings = [ 'MTkxMTMxOTkyMzcxNzg5ODcy.B3G_W0.pOFRk4TGe_SPNUhKrb58IVJvty6', 'ODY5NjU0MDYwNzkyOTM5NTEw.XqCHPX.bNW7X8fayguYEnVBmRkMvejlG4s', 'MjY4MzU4MjQwMTMyMTE3ODky.HlytHz.JOehsSFExPn1T_7RkoQq8LrZwjK', 'NDY4MTMxOTg5NjE2NjI1NjUz.ZvEGgz.3tHiZ80sc64WyQV5fr-Fklhax_O', 'NjUwNzM1Mzc3MzA0MDk1OTgd.Pr75Ph.JtTLUwxZWHaqc5jmvoueS0h6KGY', 'MTgzNTY4ODkyODAxMDMwOTE5.FKIb9Z.41SZmRhuPVXYAtienEsH2pG6075' ] def runme(self): editor.beginUndoAction() for search_string in self.list_of_strings: # uncomment the regex_string below that matches your desired behavior: regex_string = r'(?-is)^.*\Q' + search_string + '\E.*$(\R|\Z)' # match the string anywhere on the line in the active file #regex_string = r'(?-is)^\Q' + search_string + '\E$(\R|\Z)' # match the string only if it matches the whole line in the active file editor.rereplace(regex_string, "") editor.endUndoAction() if __name__ == '__main__': forum_post22331().runme()
-
-
@peterjones Thank you so much, much appreciated
it works, and somehow it should be included into notepad++ future -
@handa-flocka said in multiple search and remove:
somehow it should be included into notepad++ future
No, it shouldn’t.
-
Hello, @handa-flocka, @peterjones, @alan-kilborn and All,
Just tried your script, Peter and it wokrs like a charm ! Of course, the list of strings can be displayed in any order !
Now, regarding your attempt to find a previous script, on this topic, maybe it could be related to this @ekopalypse’s script :
https://community.notepad-plus-plus.org/post/57173
and the @alan-kilborn’s subsequent modification :
https://community.notepad-plus-plus.org/post/57229
Changes are, of course, needed to fit this present topic !
BR
guy038