Looking for a RegEx Find and Replace Visual Studio addons
I am looking for a Visual Studio Addon which does standard Regular Expression Find and Replace, not the Microsoft Visual Studio vers开发者_如何转开发ion of Regular Expression
As you do not get the complete syntax
Please help?
Thanks
This one works with Visual Studio 2008 and uses the .Net Regex syntax: .NET Regular Expressions Find and Replace Add-In for Visual Studio 2008.
Please take a look here: The Visual Studio IDE and Regular Expressions
There's a free add-in available which offers real regular expression searching in Visual Studio.
You could always write a VB.Net macro to do this; depending on how flexible you want it to be.
For Find and Replace on the current document, you could use this simple script - ALT+F11 to fire up the macro editor and then away you go. Paste this sub into a new Module:
Sub RegexReplace()
Dim regex As String = InputBox("Enter regex for text to find")
Dim replace As String = InputBox("Enter replacement pattern")
Dim selection As EnvDTE.TextSelection = DTE.ActiveDocument.Selection
Dim editPoint As EnvDTE.EditPoint
selection.StartOfDocument()
selection.EndOfDocument(True)
DTE.UndoContext.Open("Custom regex replace")
Try
Dim content As String = selection.Text
Dim result = System.Text.RegularExpressions.Regex.Replace(content, regex, replace)
selection.Delete()
selection.Collapse()
Dim ed As EditPoint = selection.TopPoint.CreateEditPoint()
ed.Insert(result)
Catch ex As Exception
Finally
DTE.UndoContext.Close()
DTE.StatusBar.Text = "Regex Find/Replace complete"
End Try
End Sub
Save the module, go back to VS and open the 'Macro Explorer'; navigate to the macro and double-click it to run (sorry if you know all this - just trying to be thorough!). You can later assign a keyboard shortcut to this macro too.
Obviously if you want all the functionality that the existing find/replace dialog provides then you have to do more work; and might be put off by that.
The most obvious enhancement to this code (apart from proper error handling!) would be to build a form on the fly with all the input boxes you need rather than displaying successive input boxes!
Just an idea ;)
精彩评论