Question

I'd like to perform a search of an entire 2013 visual studio solution to find all duplicate strings matching a regular expression. My exact case is finding duplicate implementations of a stored procedure. So I'd like to search for something like 'PROC_*' but only report duplicate matches.

I don't think this is possible using regular expressions but maybe VS can do it?

Was it helpful?

Solution

I don't think VS can do it but you have a couple of options...

1) Write a small script/program to recurse over the files in the solution folder , then run a regex over each line and keep a dictionary of match values to counts. Anything with a count over 1 will indicate a duplicate.

2) Use a utility such as TextDistil (www.textdistil.com). [Full disclosure - I'm the author and the current release is really only a beta.]. Use the following steps...

  • Create a new session ALT-W,N
  • use Session/Load all files from folder. Browse to the folder containing your solution and use *.cs as a pattern. Make sure the 'recurse' box is checked.
  • Use the "count matches" recipe with an expression that matches your needs.
  • Use a the 'remove lines containing' recipe with match ^1\s+ to remove only single matches.
  • At this point you should be left with the duplicates. Unfortunately the tool doesn't (yet) support jumping back to the originating file but armed with the list of duplicates you should be able to use VS 'find in files' from that point.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top