Community
    • Login

    How would i combine Every 3 Lines together?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    helphelp
    3 Posts 2 Posters 8.5k 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.
    • Aaron MCA Offline
      Aaron MC
      last edited by

      lets say i have a list in order such as :
      1
      2
      3
      4
      5
      6
      7
      8
      9
      etc.

      How would i be able to make Line 1, 2, 3 Join together so they look
      123,
      and also how would i do it with the rest of the text?
      so in the end it should be
      123
      456
      789
      etc.

      What im trying to do is Make Every 3 Lines join. Im not sure how to and if i press Ctrl + J after highlighting the first three it takes forever to do all manually.

      1 Reply Last reply Reply Quote 0
      • guy038G Offline
        guy038
        last edited by guy038

        Hello, @aaron-mc,

        Not difficult with regular expressions !!

        So, from your example, to get the text :

        123
        456
        789
        

        use the reges S/R, below :

        SEARCH (?-s)^(.+)\R(.+)\R(.+)\R

        REPLACE \1\2\3\r\n

        Of course, don’t forget to check the Regular expression search mode !

        Notes :

        • The first part (?-s) means that any dot, in the regex, will stand for an unique standard character, exclusively

        • Then, the symbol ^ is an assertion, looking for a beginning of line

        • Next, the part (.+)\R, searches an entire, NON empty, line, with its End of Line characters, whatever they are and stored as group 1, due to the parentheses

        • Finally, the two next syntaxes (.+)\R look for the next two complete lines, stored as group 2 and group 3

        • In replacement, these three lines are re-written, one after another, on a same line, followed by the Windows End of Line characters. For Unix files, use the regex \1\2\3\n, instead


        For a real text example, as below :

        This
        is
        a
        very
        simple
        text
        to
        test
        if our
        S/R
        works
        properly !
        

        We would obtain the text :

        This is a
        very simple text
        to test if our
        S/R works properly !
        

        Remark :

        • Of course, as the different words must be separated by a space character, the replace regex must be changed into the regex :
          \1 \2 \3\r\n, with a space character after the \1 and \2 back-references !

        Best Regards,

        guy038

        1 Reply Last reply Reply Quote 0
        • Aaron MCA Offline
          Aaron MC
          last edited by

          Thank you man it worked! You came clutch for me. :)

          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