Saturday, June 26, 2010

Using Regular Expression Groups in Search and Replace

I needed to convert a series of numbers as in:

          19473
          20390
          22797
          23116
          ..

into

          list.Add(19473);
          list.Add(20390);
          list.Add(22797);
          list.Add(23116);
          ...

While I am not adverse to doing this manually or thru some macro, I was staring at 10000 of these so I can just hear my old boss saying "You are not lazy enough."

The solution is to use regular expressions. Using NotePad++,

 SearchAndReplace

The key here was to enclose in parenthesis the search pattern and reference that in the replace string as \1.

Sweet!

No comments: