Sunday, June 29, 2014

notepad++ regex replace group

Problem
I am updating legacy code where assignments can be done in two ways:
Way 1 - set field to value;
Way 2 - field = value;

I'm used to Way 2, so i want to mass update Way 1 to Way 2 in order to make it more readable.

Solution
Using Notepad++ using the Replace tool with regex.

1. In Search Mode choose Regular expression. Make sure "Wrap around" is checked.

2. Capture groups are done by using parentheses. So in Find what put set (.+) to (.+);

3. Then you can use the value from the capture group by using \#. So in Replace with put \1 = \2;

Reference
http://stackoverflow.com/questions/3218063/notepad-replace-problem

No comments:

Post a Comment

There was an error in this gadget