Visual Studio.NET: Remove auto-generated IDs macro

After finally having enough of Visual Studio.NET adding “TextBox1″-style IDs/Names to my ASP.NET templates as I pasted them, I thought I’d write a Macro to remove them. Basically the Macro removes any ID or Name attribute that has the value of the tagname plus at least 1 number, namespace/tagprefix’s are supported (and ignored).

It can be quite handy if assigned to an “HTML Editor HTML View” shortcut (I used CTRL+ALT+SHIFT+I) to automatically remove the attributes that VS.NET adds.

Macro code is as follows:

Imports EnvDTE
Imports System.Diagnostics

Public Module TextMacros

    Public Sub RemoveGeneratedIDs()

        DTE.Find.Action = vsFindAction.vsFindActionReplaceAll
        DTE.Find.FindWhat = "\<{([a-zA-Z0-9]+\:)*}{[a-zA-Z0-9]+}{.@}:bID=\""\2:z+\"""
        DTE.Find.ReplaceWith = "<\1\2\3"
        DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
        DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr
        DTE.Find.Execute()

        DTE.Find.FindWhat = "\<{([a-zA-Z0-9]+\:)*}{[a-zA-Z0-9]+}{.@}:bNAME=\""\2:z+\"""
        DTE.Find.Execute()

        DTE.Find.FindWhat = " "
        DTE.Find.ReplaceWith = ""
        DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxLiteral

    End Sub

End Module

Enjoy

PS. I hate the VS.NET pattern syntax, why can’t it be standard Regex?