Regex assistance in Notepad++ replacing
-
When you replace stuff in notepad++ with regex, can you somehow copy over to the replace part of the text? For example in the following list:
abcd
123
123
123
123
cdsa
234
234
234
234I’d like to achieve this result:
abcd,123,123,123,123
cdsa,234,234,234,234I can select only the “\r\n” before the numbers with something like: \r\n\d+, question is, is there a way to copy over those numbers I catch with the regex to the “replace with” section.
Or maybe use some kind of regex that looks what follows the \r\n, not quite sure how to write that though.
-
You can use a backreference in your find/replace parameters. In the find box, put parenthesis around what you want to save, and then put a “\1” in the replace box to represent the set of characters found in the parenthesis set.
Find: \r\n(\d+?)
Replace with: ,\1I’m sure someone will be able to flesh this answer out and give a better explanation, but this should get you going.
-
Hello, @danailkazakov, @cipher-1024 and All,
The cipher-1024’s regex S/R works fine, but I think we can even simplify it ! I propose the following S/R :
SEARCH :
\R(?=\d)
REPLACE :
,
-
The part
\R
searches for any kind of EOL ( Windows, Unix or MAC form ) -
But the matching will be true, ONLY IF the EOL character(s) is(are) followed by any digit, due to positive look-ahead construction
(?=\d)
-
In replacement, the EOL character(s), matching that condition, are simply changed by a comma
Best Regards
guy038
-
-
Thanks, that worked great.