Reputation: 1844
To add more precision to floating point numbers, I have to go through a bunch of C# classes and, wherever there is a division operation, multiply both the numerator and denominator by 1000. So suppose we have a numerator, n and a denominator, d. Then the original would look like this: n / d. And I would need to change it to (n*1000)/(d*1000).
To search for all the division operators I'm using the find function (ctrl+f) in Visual Studio 2013 Ultimate. I'm searching for all '/'. The problem is that the find function also picks up the slashes in the comments. How can have the find function only find the single slash '/' and not the double slash '//'?
Thank you for any suggestions.
Upvotes: 5
Views: 1255
Reputation: 8938
Regex find (Ctrl+Shift+F with the Use Regular Expressions option checked) [^/<]/[^/>]
in your solution - basically a /
that:
/
or a <
(i.e. closing XML comment tags like </para>
)/
or a >
(i.e. standalone XML comment tags like <see cref="Foo"/>
)The only false positives I see with this approach in a quick check against a solution of ~80 projects are...
1/1/2014
)/
in comments (e.g. Note that an up/down change....
)...but others could come up depending on your code base - for example:
http://stackoverflow.com/users/1810429/j0e3gan
)/Customer/Address/City/text()
)If you consistently put spaces between the division operator and its operands, you could tighten the regex a bit to alleviate these false positives, changing it from...
[^/<]/[^/>]
...to...
[^/<] +/ +[^/>]
...where +
will match one or more spaces of course.
Upvotes: 5
Reputation: 5128
Try this regex expression:
[^/<]/[^/>]
"Not a slash followed by a slash followed by not a slash"
Upvotes: 2
Reputation: 4104
You can find single /
in VS2013 with the following using :
Ctrl
+f
(?<!/)/(?!/)
.*
Entire Solution
But, you must know that the result will be not what you really want, because, you will find XAML code, URL, ...
Upvotes: 2
Reputation: 8160
A regular expression search for (?<!/)/(?!/)
should find only single slashes, by using zero-width negative lookbehind/lookahead assertions. The .*
button in the small find dialog turns on regular expression searches. There is a checkbox under "Find options" for the full search dialog (Ctrl+Shift+F).
Upvotes: 1