• Login
Community
  • Login

Add a line

Scheduled Pinned Locked Moved General Discussion
5 Posts 3 Posters 1.2k 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.
  • C
    CJB
    last edited by Feb 14, 2022, 7:17 PM

    I want to add a line after a specific line multiple times in a block of code. For example: I want to add “The color Red” after " The color Blue" where “The color Blue” line is in the block a hundred times.

    T P 2 Replies Last reply Feb 14, 2022, 7:21 PM Reply Quote 0
    • T
      Terry R @CJB
      last edited by Feb 14, 2022, 7:21 PM

      @cjb said in Add a line:

      I want to add a line after a specific line multiple times in a block of code

      I find the question ambiguous.

      Do you want to find a specific line which exists multiple times throughout a file, then add a single line after each instance? And the might be a hundred of the instances.
      OR
      Do you want to add a specific line 100 times after each time another line exists?

      Terry

      C 1 Reply Last reply Feb 14, 2022, 7:28 PM Reply Quote 0
      • P
        PeterJones @CJB
        last edited by PeterJones Feb 14, 2022, 7:24 PM Feb 14, 2022, 7:23 PM

        @cjb ,

        Use regular expression searching . Specifically,

        • FIND = The color Blue(\R)\K
          • (\R) will match your line ending and put it in group#1
          • the \K will reset the match “cursor” so that the replacement will go after the newline
        • REPLACE = The color Red${1}
          • the ${1} will put the contents of group#1 (your newline sequence) at the end of the new text
        • SEARCH MODE = Regular Expression
        • REPLACE ALL
          • cannot do one replacement at a time because of the \K

        ----

        Useful References

        • Please Read Before Posting
        • Template for Search/Replace Questions
        • FAQ: Where to find regular expressions (regex) documentation
        • Notepad++ Online User Manual: Searching/Regex
        C 1 Reply Last reply Feb 14, 2022, 7:29 PM Reply Quote 2
        • C
          CJB @Terry R
          last edited by Feb 14, 2022, 7:28 PM

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • C
            CJB @PeterJones
            last edited by CJB Feb 14, 2022, 7:32 PM Feb 14, 2022, 7:29 PM

            @peterjones Perfect, thank you! Saved me sooo much time.

            1 Reply Last reply Reply Quote 0
            3 out of 5
            • First post
              3/5
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors