Search code examples
regexreplaceresx

How to find and remove/replace data in .resx in bulk?


I have a solution with lots of .resx files. They have a particular element in many of them and I want to remove that element in each resx or replace it in bulk.

The solution is in TFS 2010 so the preference is to use Visual Studio to do the job and that way it will also checkout the files and I can create shelvesets/do checkins without having to manually check the files I need out.

The versions of VS I have available to do this are VS2010, VS2012 and VS2013 (I've heard their find/replace capabilities may be different in each version).

E.g. foo.resx content has this:

<data name="SomeName">
  <value>SomeValue</Value>
</data>
<data name="SomeOther1">
  <value>SomeValue</Value>
</data>
<data name="SomeOther2">
  <value>SomeValue</Value>
</data>

And I want to get rid of all instances of the data with name "SomeName" and leave:

<data name="SomeOther1">
  <value>SomeValue</Value>
</data>
<data name="SomeOther2">
  <value>SomeValue</Value>
</data>

Is this possible? With regex? Otherwise?


Solution

  • In Notepad++, you can use (ctrl+h, regular expression search mode):

    <data name="SomeName">\r\n.*\r\n<\/data>\r\n

    And since VS's so called "regex" is a nightmare, I won't ever answer that kind of question again. But here you go, for VS 2010:

    :b*\<data name="SomeName"\>\n:b*.*\n:b*.*data\>

    This ain't pretty.