views:

115

answers:

6

I want to find all expression variable = variable; in my source files. I use Visual Studio 2008.

The variable is any variable, for example x, i, k123, incr15.

Samples:

x = x;           // Should find
x = y;           // No match
ss12 = ss12;     // Should find
ss12 = ss12 + 1; // No match
A: 

use regular expression search.

e.g.: \w* = \w*

Arthur
It does not work.
Alexey Malistov
+1 Was reasonable at the time the original question was posted.
AnthonyWJones
A: 

Have you tried the "Find all References" feature on the context menu?

AnthonyWJones
A: 

Use 'Find in Files' functionality with 'regular expressions' selected.

Something like this should do it:

\w+\s*=\s*\w+;

Shoko
It does not work.
Alexey Malistov
A: 

Use the 'Find In Files' search.

Select/highlight your expression, then press CTRL + SHIFT + F and then click on 'Find In Files' button on the 'Find and Replace' dialog that opens

J Angwenyi
+6  A: 

Use the Find-dialog with regex ...

{:a+} = \1

will do the trick.
:a is any alphanumeric character
\1 is a backreference to everything included in {}

See here for more infos.

EDIT - in reply to the comment:

^:b*{:a+}:b*=:b*\1;

^ is the beginning of a line
:b is tab/space

EDIT2: As Kobi wrote, you should maybe use :i instead of :a

tanascius
It almost works. But it finds `pCh->KSmall = KSmall;` also.
Alexey Malistov
See my updated answer - btw. you can use $ to identify the end of a line, too ...
tanascius
Thanks. That is it.
Alexey Malistov
Both of them give false positives unless you also check the Match Case and Match Whole Word boxes (not needed for second option)
Brian Rasmussen
+4  A: 

Try:

^:Zs+{:i}:Zs*=:Zs*\1;

Data can be found here: http://msdn.microsoft.com/en-us/library/2k3te2cs%28VS.80%29.aspx

It sould also be said that such a statement gives a compilation warning:

Assignment made to same variable; did you mean to assign something else?

Kobi
+1 - the :i is even better than my :a, but my :b is better than your :Zs ^^
tanascius
Looks like it. Good game :)
Kobi
+1 - `:i` is very good.
Alexey Malistov