Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    How To Replace or Delete Text Between Numbered Lines

    Help wanted · · · – – – · · ·
    expressions replace all deleting lines
    4
    6
    461
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Tyler Naddy
      Tyler Naddy last edited by

      I’m working on my website and I want to delete or replace text between the numbered lines in notepad++ with the replace function, is there any way an expression can be written to accomplish this? Any help would be greatly appreciated.

      Ekopalypse 1 Reply Last reply Reply Quote 0
      • Ekopalypse
        Ekopalypse @Tyler Naddy last edited by

        @Tyler-Naddy

        note sure I understand correctly.
        Let’s say, you have some arbitrary text on lines 6 to 10
        and you want to have something where you can specify 6 to 10 in find what box
        and in replace with box you enter your replacement, correct?

        1 Reply Last reply Reply Quote 0
        • Tyler Naddy
          Tyler Naddy last edited by

          Correct.

          1 Reply Last reply Reply Quote 0
          • Tyler Naddy
            Tyler Naddy last edited by

            Is there any way to write that into an expression?

            Alan Kilborn 1 Reply Last reply Reply Quote 0
            • rinku singh
              rinku singh last edited by

              for Delete Text Between Numbered Lines
              it is based on specified text
              find what : (\w-?)\w+
              replace with : Empty

              for Delete Text Between word Lines
              it is based on specified text
              find what : (\d-?)\d+
              replace with : Empty

              1 Reply Last reply Reply Quote 0
              • Alan Kilborn
                Alan Kilborn @Tyler Naddy last edited by

                @Tyler-Naddy

                So, sadly, the site migration lost a reply I made to this earlier. Luckily I still had the text of most of it in an N++ tab! :)

                Here’s the earlier reply again:

                We can accomplish this by borrowing from the info found here.

                As an example, say you want to skip 3 lines at the top of file, then replace then next 5 lines with something else. Note: Another way to say it is to replace line numbers 4 through 8.

                Use this regular expression search expression to match the lines: (?-s)(?<!\x0A)^(?:.*\R){3}\K(?:.*\R){5} and do a Replace-All with whatever you’d like (replace with nothing to delete those lines).

                Note that you have to do a Replace-All and not a simple Replace due to the \K syntax used. For the details of why this works, see the earlier referenced link.

                1 Reply Last reply Reply Quote 2
                • First post
                  Last post
                Copyright © 2014 NodeBB Forums | Contributors