views:

351

answers:

3

Hi

I am looking for a Visual Studio Addon which does standard Regular Expression Find and Replace, not the Microsoft Visual Studio version of Regular Expression

As you do not get the complete syntax

Please help?

Thanks

+2  A: 

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.

Rubens Farias
Thanks Rubens,I am aware of the link you provided, the syntax link I provided show the syntax that is not available, which is why I am looking for the add-in.Unfortunately the Add-in you provided is for Visual Studio 2003.
Lucifer
Seems to work on 2005; try just to install on 2008
Rubens Farias
+1  A: 

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 ;)

Andras Zoltan
+2  A: 

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.

ShellShock
Thanks for the link :-)
Lucifer