Community
    • Login

    How to merge 2 seperate lines into 1 and add a colon in between?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    2 Posts 2 Posters 1.3k 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.
    • sani baniS Offline
      sani bani
      last edited by

      Text:

      user
      pass
      
      user1
      pass1
      
      user2
      pass2
      

      What i need:

      user:pass
      user1:pass1
      user2:pass2
      

      What can i do to solve this? I’d be glad to hear your thoughts

      Scott SumnerS 1 Reply Last reply Reply Quote 2
      • Scott SumnerS Offline
        Scott Sumner @sani bani
        last edited by

        @sani-bani

        Try this:

        Invoke Replace dialog (default key: ctrl+h)
        Find what zone: (?-s)^(.+)\R(.+)(?:\R|\z)
        Replace with zone: \1:\2
        Wrap around checkbox: ticked or unticked, as you like
        Search mode selection: Regular expression
        Action: Press Replace or Replace All button, as you like

        Here’s how it works:

        THE FIND EXPRESSION:

        (?-s)^(.+)\R(.+)(?:\R|\z)

        • [Use these options for the whole regular expression][1 ] (?-s)
          • [(hyphen inverts the meaning of the letters that follow)][1 ] -
          • [Dot doesn’t match line breaks][1 ] s
        • [Assert position at the beginning of a line (at beginning of the string or after a line break character) (carriage return and line feed, form feed)][2 ] ^
        • [Match the regex below and capture its match into backreference number 1][3 ] (.+)
          • [Match any single character that is NOT a line break character (line feed, carriage return, form feed)][4 ] .+
            • [Between one and unlimited times, as many times as possible, giving back as needed (greedy)][5 ] +
        • [Match a line break (carriage return and line feed pair, sole line feed, sole carriage return, vertical tab, form feed)][6 ] \R
        • [Match the regex below and capture its match into backreference number 2][3 ] (.+)
          • [Match any single character that is NOT a line break character (line feed, carriage return, form feed)][4 ] .+
            • [Between one and unlimited times, as many times as possible, giving back as needed (greedy)][5 ] +
        • [Match the regular expression below][3 ] (?:\R|\z)
          • [Match this alternative (attempting the next alternative only if this one fails)][7 ] \R
            • [Match a line break (carriage return and line feed pair, sole line feed, sole carriage return, vertical tab, form feed)][6 ] \R
          • [Or match this alternative (the entire group fails if this one fails to match)][7 ] \z
            • [Assert position at the very end of the string][8 ] \z

        THE REPLACE EXPRESSION:

        \1:\2

        • [Insert the text that was last matched by capturing group number 1][9 ] \1
        • [Insert a colon][10 ] :
        • [Insert the text that was last matched by capturing group number 2][9 ] \2

        Created with RegexBuddy

        [1 ]: https://www.regular-expressions.info/modifiers.html
        [2 ]: https://www.regular-expressions.info/anchors.html
        [3 ]: https://www.regular-expressions.info/brackets.html
        [4 ]: https://www.regular-expressions.info/dot.html
        [5 ]: https://www.regular-expressions.info/repeat.html
        [6 ]: https://www.regular-expressions.info/nonprint.html
        [7 ]: https://www.regular-expressions.info/alternation.html
        [8 ]: https://www.regular-expressions.info/anchors.html#az
        [9 ]: https://www.regular-expressions.info/replacebackref.html
        [10 ]: https://www.regular-expressions.info/characters.html

        RegexBuddy settings to emulate N++ regex engine: Application=boost::regex 1.54-1.57 / flavor=Default flavor / replacement flavor=All flavor / ^$ match at line breaks / Numbered capture / Allow zero-length matches

        1 Reply Last reply Reply Quote 1

        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