This is a really quick sample of using Regular Expression in Visual Studio .Net to perform and intelligent Find and Replace. Documented mainly so I don?t forget it.
The need for this arose when I was extracting properties from a class, so that the data of the class was separate from the functionality.
Unlike normal regular expressions, Visual Studio doesn?t let you reference groups derived in the expression, instead a different syntax is used as {?} to tag parts of the string, and then in your replacement expression you refer to those tagged parts by \n (0 being everything, and then 1, 2, 3, etc for the individual tagged parts).
Find
public {[A-Za-z\<\>\[\]]*} {[A-Za-z]*} \{ get\; private set\; \}
Replace With
public \1 \2 \{ get \{ return someClass\.\2\; \} private set \{ someClass.\2 \= value\; \} \}
Note* Be sure to check ?Use: Regular expressions? in the Find and Replace dialog box.
For more details see: http://msdn.microsoft.com/en-us/library/2k3te2cs(VS.80).aspx
ed349c9b-e94a-4cf1-b4d5-442fa23c1752|0|.0