Yesterday, JetBrains announced the first public EAP of ReSharper 9! While I’m sure they will dedicate whole blog posts about the new (and truly amazing!) features of ReSharper 9, I wanted to beat JetBrains to the punch, and let you know about one incredible feature (which I consider a killer feature of ReSharper 9). I am talking about the improvements in dealing with Regular Expressions (Regex)!
Update: read all about the new Regex support in all its glory on the JetBrains blog!
There were always 2 ways to write regular expressions in C# code - either inside one of the methods of Regex class, e.g. Regex.IsMatch
, or defining a string literal as a constant, and using it in a Regex class later.
ReSharper 9 has Syntax Highlighting and Code Completion for regex literals! When you start typing a regex into a Regex class, you’ll see a list of suggestions, which is being narrowed down as you type:
![Code Completion](/2014/10/regular-expression-enhancements-in-resharper-9/regex1.png)
There’s also a special syntax highlighting for the complete regex - as well as automatic checking for errors:
![Syntax Highlighting](/2014/10/regular-expression-enhancements-in-resharper-9/regex2.png)
However, the killer feature is the ability to validate and test the regular expressions straight from Visual Studio! Pressing Alt-Enter anywhere inside the expression will bring the Quick Actions menu, with a new option to Validate regular expression:
![Regex validation menu](/2014/10/regular-expression-enhancements-in-resharper-9/regex3.png)
Which opens a new window that lets you input some text to validate your regular expression!
![Regex validatior](/2014/10/regular-expression-enhancements-in-resharper-9/regex4.png)
But the best part of these new enhancements is the ability to transform any string literal into a regular expression! Simply press Alt-Enter inside the string literal, and select Make regular expression here:
![Turn into regex](/2014/10/regular-expression-enhancements-in-resharper-9/regex5.png)
Will turn into:
![With syntax highlighting](/2014/10/regular-expression-enhancements-in-resharper-9/regex6.png)
And you get all the regex features (validation, intellisense, etc) inside your regex string literals! Amazing!