Reputation: 87
I am trying to figure out how to do a find and replace on Notepad++ using regex, what I have is a bunch of lines with the following format
1 ; 2 ; 3 ; 4 ; AA ; AA BB
5 ; 6 ; 7 ; 8 ; AA ; BB CC
2 ; 4 ; 6 ; 0 ; AA ; DD EE
What I'd like to do is add a semicolon in between every instance of the last section like this:
1 ; 2 ; 3 ; 4 ; AA ; AA ; BB
5 ; 6 ; 7 ; 8 ; AA ; BB ; CC
2 ; 4 ; 6 ; 0 ; AA ; DD ; EE
Any ideas?
Thanks!
Upvotes: 1
Views: 1563
Reputation: 71578
Try this regex in find:
(\S+)$
(read as 'space', then the characters (\S+)$
)
And this replace:
; $1
(read as 'space', semicolon, 'space' and 'dollar 1')
Make sure that you checked "Regular expression" and that ". matches newline" is unchecked!
\S
matches non-spaces (non-newlines, non-carriage returns non-formfeeds) and the brackets stores the match in a variable $1
in this case.
$
matches the end of the line.
In the replace, we're putting space, semicolon, space then the stuff we earlier stored in $1
.
Upvotes: 1
Reputation: 5666
So this is the regex to match last two characters with a space:
(\s\w\w)$
Remember to add multiline flag to your regex.
Replace matched elements with ; $1
. $1 stays for first capturing group.
Demo: regexr.com
Upvotes: 0