There was a need for a large piece of code to make a massive replacement. I use the regular Visual Studio 2017 tool and regular expressions to search. I mean that the syntax of expressions in the search string corresponds to the syntax of regular expressions in C #. There is the next line

get_Label (). get_UserLocalizedLabel (). get_Label ();

In the search set the expression get_(\w*)\(\)

I get the search result:

get_Label() . get_UserLocalizedLabel() . get_Label() ;

And here we need this result:

get_ label () . get_ UserLocalizedLabel () . get_ Label () ;

That is, you must exclude the word between get_ and () . I tried get_(?!\w*)\(\) , but did not succeed.

  • And in the end what should happen? Do I need to replace _get_ and () with something (for example, to get GetLabel.GetUserLocalizedLabel , or completely remove them, or something else? - Regent
  • one
    Oh, reworking the code from Java ... - Qwertiy
  • @Qwertiy aha, it delivered to me too :). Only this is not Java, this is decompiling Resharper so processed processed :) - Dismantled

1 answer 1

If you need to replace get_ and () with something, then this option will do:

Find what:

 get_(\w*)\(\) 

Replace with:

 Get$1 

For

get_Label (). get_UserLocalizedLabel (). get_Label ()

result:

GetLabel.GetUserLocalizedLabel.GetLabel

  • The end result should have been GetLabel.GetUserLocalized.Label I would be grateful if you explain how $ 1 works. In my example, I showed that highlights when searching Studio. I thought about making the necessary selection and replacing it with an empty string. But $ 1 has simplified everything. - Dismantled
  • @Dismantled $1 is the first group found. Group is part of reg. expressions in brackets. In this case, \w* . If the string is always get_Label().get_UserLocalizedLabel().get_Label() , then you can get GetLabel.GetUserLocalized.Label using the get_(\w*)\(\)\.get_(\w*)\(\)\.get_(\w*)\(\) replacement get_(\w*)\(\)\.get_(\w*)\(\)\.get_(\w*)\(\) on Get$1.Get$2.$3 . Not tested, but should work. If all get_X are replaced separately, then you must somehow distinguish the first get_Label and the last. - Regent
  • Super! I thought about that. Thank you very much! Save me a couple of hours of sleep :). - Dismantled