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
\Rsearches 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.
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