Mark's Blog About Search Activity

Visual Studio Regex addin (now for 2008)

Visual Studio’s regex implementation is non-standard. Thankfully, there’s an open source add-in for VS2008 that allows you to use “standard” regular expressions found here.

“Why do I care?” Here’s a very useful example of why regex is so cool: Say you wanted to replace all calls to a function, like IsNothing(…) and replace it with a native sytnax … Is Nothing  (and Not IsNothing(…) with … IsNot Nothing)

You can just use this search string (set ignore pattern whitepace):

(?Not(?:\s))?IsNothing\((?(?>[^()]+|\((?)|\)(?))*(?(number)(?!)))\)

Expanded:

(?Not(?:\s))?  
IsNothing\((?  
    (?>  
        [^()]+   
        |    \( (?)  
        |    \) (?)  
    )*  
    (?(number)(?!))  
    )  
\)

With this replace string: ${inner} Is${prefix} Nothing

If you liked this post, you can share it with your followers or follow me on Twitter!
comments powered by Disqus