Community
    • Login

    Repeat lines and add empty lines after every line

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 3 Posters 272 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.
    • J
      johnny johnson
      last edited by

      Hello.

      I need two different things done.

      I have a list like this:

      A
      B
      C
      

      The first formating I need it to convert to:
      (Repeat each line three times)

      A
      A
      A
      B
      B
      B
      C
      C
      C
      

      The second formating I need it to convert to:
      (2 empty lines after every line)

      A
      
      
      B
      
      
      C
      
      
      

      Is this easily possible with notepad++ or is it better to use another solution?

      Mark OlsonM 1 Reply Last reply Reply Quote 0
      • Mark OlsonM
        Mark Olson @johnny johnson
        last edited by

        @johnny-johnson
        Use find/replace for (regular expressions ON) for both tasks
        Get three of each line:
        FIND: (?-s).+\R
        REPLACE WITH $0$0$0
        Get three newlines after each line:
        FIND: \R
        REPLACE WITH: $0$0$0

        Reference material: https://npp-user-manual.org/docs/searching/#regular-expressions

        J 1 Reply Last reply Reply Quote 4
        • J
          johnny johnson @Mark Olson
          last edited by

          @Mark-Olson

          I noticed that the last line of the original list doesn’t get edited that way in both cases (at least on my end) - but of course I can do that manually easily ;-)
          Thanks a ton - it helps me a lot!

          Terry RT 1 Reply Last reply Reply Quote 0
          • Terry RT
            Terry R @johnny johnson
            last edited by

            @johnny-johnson said in Repeat lines and add empty lines after every line:

            I noticed that the last line of the original list doesn’t get edited that way in both cases (at least on my end) - but of course I can do that manually easily ;-)

            That’s a common issue. Often solution providers will just ask for a new last empty line to be added before running the regex (REGular EXpression). This allows the regex to work as planned. The alternative is to plan for that situation and the regex becomes more complex looking, although still relatively easy to understand. The \R refers to all line endings, except the last line in a file doesn’t have this hence why it didn’t work on that original last line.

            A question for you, you asked for these 2 steps separately, was it your intention to be using these regexes independently? It is possible to combine the 2 steps into 1 regex.

            Terry

            J 1 Reply Last reply Reply Quote 4
            • J
              johnny johnson @Terry R
              last edited by

              @Terry-R said in Repeat lines and add empty lines after every line:

              intention to be using these regexes independently

              Yes, it was my intention to be using these regexes independently - so the ones provided @Mark-Olson are perfectly fine. It’s incredible how helpful and fast responding this community is - I haven’t seen that before. Thanks a lot to you all!

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