I am refactoring a C++ codebase in Visual Studio 2005. I\'m about half way through this process now and I\'ve commented out a lot of old code and replaced or moved it. Now I\'
If you comment your old code with //
you can use regular expressions while searching for something in your codebase. Something like this for example: ^[^/][^/].*your_function_name.*
.
Previous answer gave a false-positive on cases where otherwise matching lines were placed on lines containing other source:
++i; // your_search_term gets found, don't want it found
So replaced the :b*
with .*
and added the <>
so only entire words are found, and then went after some of the older C-style comments where there's a /*
on the line:
^~(.*//)~(.*/\*).*<your_search_term>
In my case I was hunting for all instances of new
, not amenable to refactor assistance, and boatloads of false-positives. I also haven't figured out how to avoid matches in quoted strings.
My take:
yes you can use regular expressions, those tend to be too slow and thinking about them distracts from focusing on real stuff - your software.
I prefer non-obtrusive semi-inteligent methods:
Poor man's method: Find references if you happen to use intelisense on
Or even better: Visual assist and it's colored "Find all References" and "Go To" mapped to handy shortcuts. This speeds up navigation tremendously.
In Visual Basic within Visual Studio 2015, I was able to search for text outside of comments by adapting glassiko's comment from the most upvoted answer
^(?![ \t]*[']).*mysearchterm
And in C# you would use glassiko's comment exactly as it was
^(?![ \t]*//).*mysearchterm
As the other provided solutions didn't work for me, I finally discovered the following solution:
^~(:b*//).*your_search_term
Short explanation:
^
from beginning of line~(
NOT the following:b*
any number of white spaces, followed by//
the comment start)
end of NOT.*
any character may appear before your_search_term
your search term :-)Obviouly this will only work for //
and ///
-style comments.
You must click "Use Regular Expressions " Button (dot and asterisk) on your find window to apply regex search
Just to add on, as I was doing a "find all" for division operator used in the code, used the below to exclude comments as well as </
and />
from aspx files:
^~(.*//)~(.*/\*)~(.*\<\/)~(.*/\>).*/