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]+}{[email protected]}:bID="":z+"""
        DTE.Find.ReplaceWith = "<"
        DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
        DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr

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

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

    End Sub

End Module


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