delete line between bookmark

  • @pinuzzu99

    Hmmmmmm, well, first, you don’t need the boomarks. I’m not sure if you put them in just for running the script, or if they were just already there.

    Second, you have to read the prompt on the box: Enter first line # of range to delete: where, for your example, you would enter 10:


    When you say OK to that, it will ask you for the last line, where you would enter 28:


    When you do that and press OK, it will then delete your range of lines, including the first and last (10 and 28 in this example will be gone after the final OK, as well as all lines in between).

    You can press Cancel in either box to abort everything.

    Did I really make it that hard to understand??

    Sure, it could all be combined into one box, but then one has to think more about what to put in a single input box. The way I did it, you just follow the prompts.

    By the way, your first line could have been 28 and your last line 10 and it would have worked the same way.

  • Hindsight looking at the script:

    Where I call the lower function on the user_input variable probably isn’t the best place for it. They won’t fail with a ValueError and thus probably shouldn’t be part of that block. But the script DOES work as written (AFAICT), so I won’t provide a changed version.

  • @pinuzzu99, @alan-kilborn All,

    Sorry, I did not understand your need, correctly ! Indeed, you simply want, from a line, containing an e-mail address, delete all subsequent lines till the next line containing an e-mail address, excluded, don’t you ?

    If so :

    • Move to the line right after a line containing an e-mail address

      • Manually

      • Using the regex (?-s).+@.+\R\K, which places the caret at beginning of any line right after an e-mail address

    • Now, use the following regex S/R to delete all lines till the next e-mail address line

      • SEARCH (?s).+?(?=(?-s)^.+@)

      • REPLACE Leave EMPTY

    Note : I gave it a try, with 30,000 random lines between two lines containing an e-mail address and it correctly selected all this stuff in between and deleted it ;-))

    Best Regards,


  • tanxs Alan, this was what i wanted!
    and the bookmarks were only to make it clear the range i wanted to eliminate…

    tanxs for your reply. but i was hoping it could be done in one step…
    anyway work well, always thanks for your appreciated help!

  • @pinuzzu99 said in delete line between bookmark:

    but i was hoping it could be done in one step

    This implies that it is something you do often, so it might be worth recording multiple steps into a “macro” that you keep. This thread talks more about that.

    Script notes: Using bof doesn’t make much sense – it is always going to be line 1 so why not just use 1? Also, I’ve thought of some extensions to the script. I could see myself using the script often. I’ll posts an enhanced version soon!

  • tanxs for your explanation on macros.
    but, if i understand correctly, if i record a macro, for example by deleting lines 10 to 20, this macro always repeats the same procedure…
    I instead have different txt, in which the lines to be deleted are always different…
    so i think in my specific case the elimination steps have to be done manually.
    is this correct?

  • @guy038
    also your string work, but this delete all line, including line which contains the email…
    instead i want delete the lines under the email, but leave this …

  • @pinuzzu99

    I thought we were talking about several replacement operations when I brought up recording in macros. Other operations don’t lend themselves so well to “macroization”.

  • Hello, @pinuzzu99 and All,

    You said in a previous post :

    also your string work, but this delete all line, including line which contains the email…
    instead i want delete the lines under the email, but leave this …

    My method does not delete any -mail address, assuming that you put the caret at the beginning of the first line, right after the line containing this e-mail address !

    Consider the input text :

    2017-07-08 12.35.03_5.jpg                         			32KB			             08/07/2017 19:34:57
    2017-07-08 12.35.03_8.jpg                         			71KB			             08/07/2017 19:34:57
    2017-07-08 12.35.10_4.jpg                         			70KB			             08/07/2017 19:35:04
    2017-07-08 12.48.43_15.jpg                        			84KB			             08/07/2017 19:48:41
    2017-07-25 01.22.59.jpg                           			102KB			            25/07/2017 08:22:59
    • If you run the search regex (?-s).+@.+\R\K, the caret should have moved at the beginning of the line 2017-07-08 12.35.03_5.jpg, with the calltip ^zero length match

    • Then, after running the search regex (?s).+?(?=(?-s)^.+@) all the lines, after the, till the second e-mail address excluded, should have been selected, then deleted after replacement !

    But, may be, you’ll prefer this other method, which need one operation, only !

    • Move , first, to a line containing an e-mail address, if necessary. Note that the caret can be at any position in that line, with an e-mail address !

    • Then, use the following regex S/R to delete all lines, after this 1st e-mail address till the next e-mail address, excluded

    SEARCH (?-s).*\R\K(?s:.+?)(?=^.+@)




  • with first string work fine, but at one specific account all text it is selected, then deleted! but only in a specific case, maybe it contains characters that other accounts don’t contain …
    try with this txt:

    so, second string work, select all line that I want to eliminate, but then with the replace the lines are not deleted!
    i have record my screen, see video here:
    maybe i do something wrong…

  • @pinuzzu99 and All,

    Oh… I forgot to mention that you need to use the Replace All button , only. Do not use the Replace button which does not act as it should, when the regex contain any \K syntax. This is a general rule, available for any regex containing, at least, one \K syntax

    Best Regards,


  • yes i know, Replace All and i have try it before my post above, but as i said, i want check all my single block one by one before delete all lines.
    for my purpose work fine this: (?-s).*\R(?s:.+?)(?=^.+@)
    without \K and work with Replace, but on next block i need to put cursor at begin line under mail line…
    this is little problem if my txt have 10,000 block of mail - file list…

  • in this specific case string (?-s).*\R(?s:.+?)(?=^.+@) don’t find value…
    why? what is different than other blocks?
    Used: 3/50GB
    Physiology                                        			0KB
    Internal Med                                      			0KB                                     			370KB
    Lippincott Illustrated Reviews Flash Cards Physiology - Preston, Robin [SRG].pdf			42137KB			          08/09/2015 17:46:42
    Ganongs Review of Medical Physiology,  24E (2012) [UnitedVRG].pdf			80607KB			          08/09/2015 17:46:36
    Kaplan USMLE Step 1 Physiology Lecture Notes (2013) [PDF] [UnitedVRG].pdf			25312KB			          08/09/2015 12:50:40

  • @pinuzzu99 said in delete line between bookmark:

    i want check all my single block one by one before delete all lines.

    But as @guy038 said, that expression won’t work in one-at-a-time mode. Continuing to try is an exercise in futility.

    If you are uncertain whether the regex will meet all your needs, and you want to be able to compare the “before” and “after” states of your file, I recommend opening the original file blah.txt, File > Save copy as, give it a name like blah_new.txt, then open blah_new.txt and move to other view – so that the two panes of Notepad++ are blah.txt on the left and blah_new.txt on the right, then run Guy’s regex on the blah_new.txt, then use the Compare plugin (which you can install from the Plugins Admin) to find and easily navigate through the differences between the files, and make sure everything is the way you want it. If they are all right, great; if most are right and just a couple aren’t quite right, then manually fix those last few; if there are many wrong, then run Undo, and try to update the regex to better do what you want. Once you are happy with blah_new.txt, you can delete the original blah.txt (or rename to blah_old.txt, then rename blah_new.txt to blah.txt.

    (Or, you can start by copying blah.txt to blah_old.txt, and have blah_old.txt on the left and blah.txt on the right, doing all your edits to blah.txt, and eliminating the extra renames at the end of the procedure.)

  • i already save one backup of my txt…
    and yes, compare plugin, i have and already use this.
    however Document Map is very useful for scrolling through the file…

  • i hope guy038 reply to my post (4 post above above this post)…

  • Hello @pinuzzu99, @Peterjones, @alan-kilborn and All,

    Sorry, I did not even notice this post, which was rather short ;-)) Well, I suppose that the regex does not work because the last line Kaplan USMLE Step 1 ..... is not followed with an e-mail address but is just the very end of your file !

    In order that this specific case will be taken in account, too, here is a other search regex :

    • Move to any line containing an e-mail address

    • Open the Search dialog ( Ctrl + F )

    • SEARCH (?-s).*\R\K(?s:.+?)(?=^.+@|\z)

    • Tick the Wrap around option

    • Select the Regular expression search mode

    • Click on the Find Next button

    • Hit the ESC key to close the Find dialog

    • Now, hitting, repeatedly, on the F3 key, it will select all text, after this e-mail address till the next e-mail address excluded and so on… OR till the very end of current file !

    • Of course, you may manually delete some of these blocks, with the Delete key, if necessary

    • For a global suppression, leave the replacement zone empty and click on the Replace All button

    Moreover, if you want to move from one e-mail address to the next or the previous one, here is an simple method :

    • Open the Mark dialog ( Search > Mark... ) option

    • SEARCH @

    • Tick the 3 options Bookmark line, Purge for each search and Wrap around

    • Click on the Mark All button

    => Now, you can easily navigate betweens all these email addresses, using the F2 and/or Shift + F2 shortcuts

    Best Regards,


  • oh guy038 tank you so much for your reply! you are my super-hero!
    2 really interesting things. it was what i wanted! many tanxs.

    only little curiosity: at the first part of your reply, about this code (?-s).*\R\K(?s:.+?)(?=^.+@|\z) work fine for my purposes, but i don’t understand why if i click (after the text block after mail has been selected) Replace with: empty don’t delete simply this block… i have to exit the find and delete it manually with the DEL key.
    it would be very nice to remove the block with the Replace with key… it’s not possible that??

  • …again… guys038 where did you end up ??

    does not exist here in the forum the possibility to send a PM to a user? I do not think so…

  • @pinuzzu99

    Time to sit down and do some LEARNING and stop doing so much ASKING ?

Log in to reply