views:

53

answers:

2

I have a large solution with a lot of lines that I need to replace. In Visual Studio, you can search and replace with the aid of regular expressions.

I want to replace lines like:

rst.Fields("CustomerName").Value
rst.Fields("Address").Value
rst.Fields("Invoice").Value

To:

row("CustomerName").ToString()
row("Address").ToString()
row("Invoice").ToString()

Thus keeping the dynamic text part, which can vary.

Is this possible and how?

Update, solution:
Search: rst.Fields{(.*)}.Value
Replace: rst\1.ToString()

Thanks JaredPar!

+1  A: 

Try the following

  • Search Expression: ASpecificCommand(\(.*\))\.ASpecificProperty
  • Replace Expression: ATotallyDifferentCommand\1.ATotallyDifferentProperty

Note: This is not a perfect solution. Since there are (s involved and hence matching of nested parens, a regex won't ever be a perfect solution. However it should get the job done for the specific pattern you posted

JaredPar
Very very close, this did put me on the right track (using backreferences in regular expressions). The solution needs {} instead of (). Thanks!
Michel van Engelen
+2  A: 

Looks like you have it nailed. It's what is called a "tagged expression" and you can see another example here: http://blogs.msdn.com/b/zainnab/archive/2010/09/12/replace-in-files-tagged-expressions-vstipfind0016.aspx

zainnab