views:

135

answers:

1

I need to convert expressions of the form:

return *;

into:

return filter(*);

It seems simple enough to express it with wildcards, however, in visual studio's search & replace dailog, there's no way to associate the first asterisk with the second one. I suppose a regex can do this quite easily, however I know very little about regexes.

How do I express this criteria in regex?

+1  A: 

A capture group when searching/replacing with regex in VS can be given by enclosing something with curly braces.

A backreference can be given simply by using \1. There is also a menu to the right of the input fields, containing building blocks.

So you would be simply replacing

return {[^;]+};

by

return filter(\1);

The [^;]+ specifies that you want at least one character that is not a semicolon, so unless you return delegates or anonymous methods this should work fine.

Joey
+1, on earlier versions of VS, tagged expressions where inside `\(exp\)` instead of `{exp}`.
Nick D
Oh, ok, I completely overlooked the version, having used VS2k8 for quite some time now.
Joey