Friday, May 2, 2008

Convert HTML <a href/> tags to <asp:HyperLink/>

Search:
<a\s{1}href="(?<url>.*?)"(\s?target="(?<target>_(blank|new|parent|self|top))")?(\s?class="(?<class>.*?)")?(\s?style="(?<style>.*?)")?>(?<title>.*?)</a>

Replace:
<asp:HyperLink ID="HyperLink1" runat="server" Target="${target}" CssClass="${class}"
NavigateUrl="${url}">${title}</asp:HyperLink>

There is room for improvement but it will do the job. You may want to use another editor than Visual Studio as it doesn't like this regex