Take the 2-minute tour ×

How do I use regular expressions and search and replace to turn this

[UserID] = <UserID, int,>
[UserID] = 123123
[UserID] = asd123123

[UserID] = [UserID]
[UserID] = [UserID]
[UserID] = [UserID]

In other words I want to take everything from left side of the line up to the '=' character and replace everything on the right side of the '=' with the match from the left side. We can assume a line break at the end of each line.

What are my Find what: and Replace with: values? (I'm using Notepad++)

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Notepad++ uses ERE (Extended Regular Expressions). This is the regex I would use:

Find: ^([^\]]*]) = .*

Replace with: \1 = \1

share|improve this answer

This is how I would do it in vim:

:%s/\[\(\w\+\)\]\s\+=\s\+.*$/[\1] = [\1]/

Others might be a variation of it, a long the lines of:

search  : \[(\w+)\]\s+=\s+.*$
replace : [$1] = [$1]
share|improve this answer

Your Answer


