Robs
Robs

Reputation: 8279

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 version of Regular Expression

As you do not get the complete syntax

Please help?

Thanks

Upvotes: 3

Views: 2080

Answers (3)

Polyfun
Polyfun

Reputation: 9639

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.

Upvotes: 5

Andras Zoltan
Andras Zoltan

Reputation: 42353

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

Upvotes: 2

Rubens Farias
Rubens Farias

Reputation: 57956

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.

Upvotes: 3

Related Questions