Community
    • Login

    How find range of lines by their number?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    2 Posts 2 Posters 2.1k Views 2 Watching
    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.
    • Obada KurdiO Offline
      Obada Kurdi
      last edited by

      I have range of lines with from (1-189). I want to enter an expression in (Replace) to find these lines so I can replace them with something.

      Thank you

      Scott SumnerS 1 Reply Last reply Reply Quote 0
      • Scott SumnerS Offline
        Scott Sumner @Obada Kurdi
        last edited by

        @Obada-Kurdi

        Okay, so technically it isn’t possible to directly say “Replace lines X through Y” with something else. That being said, there are some ways to achieve the goal.

        In your specific case, with X=1 and Y=189, it becomes fairly easy:

        Step 1: Move your caret to the very top of your file (important)

        Step 2: Execute the following “Replace” operation (not “Replace All”!):

        • Find-what: (?-s)(.*\R){189}
        • Replace-with: whatever you want
        • Search-mode: Regular expression

        However, in the general case (where the starting line X is NOT equal to 1), things are more interesting/tricky. Here’s a solution for that general case, unfortunately it requires you to do some mental math:

        Step 1: Move your caret to the very top of your file (important)

        Step 2: Execute the following “Replace” operation (not “Replace All”!):

        • Find-what: (?-s)(.*\R){S}\K(.*\R){L}
        • Replace-with: whatever you want
        • Search-mode: Regular expression

        where:

        • S is the one less than the desired starting line number, note S = X - 1
        • L is the number of lines it is desired to replace, note L = Y - X + 1

        because (from the problem statement):

        • X is the FIRST line to replace with other data
        • Y is the LAST line to replace with other data

        This technically isn’t a Notepad++ question, but more of a Boost regular expression engine question, so I’m reluctant to put forward this solution here, due to less tolerance lately for non-Notepad++ discussion. However, this does have an important N++ implication regarding where the caret is when the replacement is conducted.

        If this (or ANY posting on the Notepad++ Community site) is useful, don’t reply with a “thanks”, simply up-vote ( click the ^ in the ^ 0 v area on the right ).

        1 Reply Last reply Reply Quote 0

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors