views:

129

answers:

2

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

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

into 
[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++)

A: 

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]
Maxwell Troy Milton King
+2  A: 

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

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

Replace with: \1 = \1

tiftik