Search code examples
regexvisual-studio-2015replacefindfind-replace

In Visual Studio, is there a way to specify an object type when doing a regular expression find and replace?


In Visual Studio, is there a way to specify an object type when doing a regular expression find and replace? I'm trying to do a find and replace in Visual Studio but I only want to do it on objects that are of a specific object type (I want to only do this on strings, and not any other object type).

This is my regex query:

  • FIND: (Me\.(?:(?!.*Exclude).*?)) Is Nothing[^"]
  • REPLACE: String.IsNullOrWhiteSpace($1)

If this capability isn't built in to Visual Studio, is there an extension or something else I could use to do this with?


Solution

  • No, you can't specify the type of the object in the regex, since it's looking for a string pattern and have no idea of what the string really is.

    I would give a shot with ReSharper but I'm not 100% positive that it can do such things.