Community
    • Login

    How To Replace or Delete Text Between Numbered Lines

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    regexreplace alldeleting lines
    6 Posts 4 Posters 830 Views
    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 NaddyT
      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.

      EkopalypseE 1 Reply Last reply Reply Quote 0
      • EkopalypseE
        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 NaddyT
          Tyler Naddy
          last edited by

          Correct.

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

            Is there any way to write that into an expression?

            Alan KilbornA 1 Reply Last reply Reply Quote 0
            • rinku singhR
              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 KilbornA
                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
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors