How to merge 2 seperate lines into 1 and add a colon in between?
-
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
-
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 likeHere’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
- [(hyphen inverts the meaning of the letters that follow)][1 ]
- [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 ]
+
- [Between one and unlimited times, as many times as possible, giving back as needed (greedy)][5 ]
- [Match any single character that is NOT a line break character (line feed, carriage return, form feed)][4 ]
- [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 ]
+
- [Between one and unlimited times, as many times as possible, giving back as needed (greedy)][5 ]
- [Match any single character that is NOT a line break character (line feed, carriage return, form feed)][4 ]
- [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
- [Match a line break (carriage return and line feed pair, sole line feed, sole carriage return, vertical tab, form feed)][6 ]
- [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
- [Assert position at the very end of the string][8 ]
- [Match this alternative (attempting the next alternative only if this one fails)][7 ]
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.htmlRegexBuddy 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
- [Use these options for the whole regular expression][1 ]