Find term and delete the line above

  • Hi everyone!
    First of all, I’m very noob…

    So I need to delete a specific line, the content changes, but is always above a specific term, I made the following test and the result is what I want, but on NP++ seems not work:


    I need to do it on several files, something like 2k, but is not working even on single file.

    Sorry my bad english and thanks in advance!

  • @Watashi ,

    it would have been nice to embed the sample text and sample regex (?:.*\n){1} End Object in your post, rather than making us follow an external link.

            ... way too much text, that's completely irrelvant...
         End Object

    But when I put in that FIND, it finds one occurrence:
    – but it appears that it’s only selecting the EOL through the next line.

    Oh, wait, your regex just has \n. If you’re in windows, the EOL marker is \r\n. Unless you have . matches newline enabled (or (?s) in the regex), the .* will not match \r or \n. So .*\n then can only match a zero-width .* followed by the \n before the line you’re really looking for.

    If you have normal Windows EOL shown in your status bar, bfaae1e5-94af-4a7b-b520-5c3f1d19fb07-image.png , then you need to look for \r\n… or, to be able to handle different file types, \R will match \r, \n, or \r\n.

    So change your regex to (?:.*\R){1} End Object . In my experiment, that removed the specific line before the End Object line

    Also, as regex101 told you, the {1} was useless (unless that’s just a simplified version of your search-regex, and really you are capturing multiple lines before the End Object).

  • @PeterJones Sorry about the link, I’ll keep that in mind for the next time!

    Oh, you’re right, {1} is not needed for single line :O

    “Not every hero wears a cape” =D


    Did work like a charm * – *

    Thank You so much!

Log in to reply