6c00h
6c00h

Reputation: 87

Notepad++ Regex Find Semicolon Second Last From Newline

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

Answers (4)

Jerry
Jerry

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

krisku
krisku

Reputation: 3991

Search for: (\w+)\s+(\w+)$
Replace with: \1 ; \2

Upvotes: 1

Adam Wolski
Adam Wolski

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

Ravi K Thapliyal
Ravi K Thapliyal

Reputation: 51721

Find what: ([A-Z]+)\s+([A-Z]+)$
Replace with: $1 ; $2

Upvotes: 2

Related Questions