delete line between bookmark

  • @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 ?

  • dear sir… if i knew how to do it, I wouldn’t be here to waste time and ask others for advice, don’t you think?
    think before writing, your speech is not welcome.
    please avoid writing in my posts, your post is not required.

  • @pinuzzu99 said in delete line between bookmark:

    does not exist here in the forum the possibility to send a PM to a user?

    No, there is no PM capability.

    if i knew how to do it, I wouldn’t be here to waste time and ask others for advice, don’t you think?

    Guy has pointed you to the regex FAQ in your very first thread here. And again in your fourth thread here. Then, in your fifth thread, he again reminded you to follow Alan’s advice and learn the basics of regular expressions.

    You need to show more effort, rather than demanding that we do your homework for you (at least, I hope it’s homework; if we’re doing the job you are being paid to do for you, that’s even worse), on your time schedule.

    your speech is not welcome.
    please avoid writing in my posts, your post is not required.

    I am sorry. You don’t get to decide who replies to your posts. Alan’s advice is sound advice: you need to put in the effort to start learning this.

    In less than a month, you have done 6 different topics, four of which are regex based; as Guy pointed out, some of those have had very similar requirements. You have seen dozens of different regex suggestions from Guy and others on the forum. It is time for you to start learning what the bits of the regexes do, and try them yourself. If you get stuck, you can show us what you tried, and explain why you thought it should work, and we might be able to explain to you why it didn’t work for you, and point you in the right direction.

    Please read the regex FAQ that has been linked for you. If that takes you to too many different locations, then please just focus on the official Notepad++ regex documentation.

    Some more of my standard advice for people asking regex questions follows below:

    Please Read And Understand This

    FYI: I often add this to my response in regex threads, unless I am sure the original poster has seen it before. Here is some helpful information for finding out more about regular expressions, […]:


    If you have further search-and-replace (“matching”, “marking”, “bookmarking”, regular expression, “regex”) needs, study the official Notepad++ searching using regular-expressions docs, as well as this forum’s FAQ and the documentation it points to. Before asking a new regex question, understand that for future requests, many of us will expect you to show what data you have (exactly), what data you want (exactly), what regex you already tried (to show that you’re showing effort), why you thought that regex would work (to prove it wasn’t just something randomly typed), and what data you’re getting with an explanation of why that result is wrong. When you show that effort, you’ll see us bend over backward to get things working for you. If you need help formatting, see the paragraph above.

    Please note that for all regex and related queries, it is best if you are explicit about what needs to match, and what shouldn’t match, and have multiple examples of both in your example dataset. Often, what shouldn’t match helps define the regular expression as much or more than what should match.

    Here is the way I usually break down trying to figure out a regex (whether it’s for myself or for helping someone in the forum):

    1. Compare what portions of each line I want to match is identical to every other one (“constants”), and what parts do I want to allow to be different in each line (“variables”) but still be part of the match.
    1. Look at both the variables and constants, and see what portions of each I’ll want to keep or move around, vs which parts get thrown away completely. Each sub-component that I want to keep will be put in a regex group. Anything that gets completely thrown away doesn’t need to be in a group, though sometimes I put it in a numbered (___) or unnumbered (?:___) group anyway, if I have a good reason for it. Anything that needs to be split apart, I break into multiple groups, instead of having it as one group.
    1. For each group, I do a mental “how would I describe to my son how to correctly match these characters?” – which should hopefully give me a simple, foolproof algorithm of characters that must match or must not match; then I ask, “how would I translate those instructions into regex sequences?” If I don’t know the answer to the second, I read documentation, or ask a specific question.
    1. try it, debug, iterate.

Log in to reply