HREF Tags - to - Text Demo

This demo illustrates how to use regular expressions to convert HREF tags into text tags. The below page is a saved version of the HTML from Note the "links" on the left hand column, for instance. They are HTML hyperlinks on the ASP.NET page, but here, I have used regular expressions to turn them into text links with the following format: URL Description [URL].

Welcome to the ASP.NET Home Page
  Home []
  Newsgroups []
  Discussions []
  Samples []
  Books []
  Articles []
  Events []
  FAQ [] []
  ASP Next Gen [] [] []
  ASP Today [] [] []
  411ASP.NET Directory [] [] [] [] [] []
  Dot NET Books []
  Dot NET Wire [] []
  ASP 101 []
  ASP Wire []
  ASP Watch []

ASP Computer Products
can be found at its new address: Click here [].


ASP.NET is a revolutionary new programming framework that enables the rapid development of powerful web applications and services. Part of the emerging Microsoft .NET Platform, it provides the easiest and most scalable way to build, deploy and run distributed web applications that can target any browser or device.

Step 1: Download and Install ASP.NET
The Beta 1 Release of ASP.NET is now available. This release is supported on Windows 2000 -- both server and workstation editions.
Click here to download ASP.NET and the .NET Framework SDK []
Also available as a separate download are the ASP.NET Mobile Controls. These enable developers to easily target mobile devices (WAP-enabled cell phones, Pocket PCs, etc) using ASP.NET.
Click here to download ASP.NET Mobile Web SDK []

Step 2: Explore the Samples and Tutorials
The .NET Quickstart Tutorials include over 900 samples that demonstrate ASP.NET and the .NET Framework. They can be installed locally as part of the SDK, or run online from [].
We have also built comprehensive, end-to-end e-commerce and portal applications using ASP.NET and the .NET Framework. You can run and explore the source code online at [].

Step 3: Join the Discussion Lists
There are a number of great e-mail-based discussion lists for ASP.NET. The Microsoft ASP.NET team regularly participates in the discussions and posts sample code.
To join the ASPNG discussion list (one of the most active 3rd party lists), select your preferences and submit the form below:
Your Email:  

List Name Topics (number of posts/day)
 aspngcommunity general posts and announcements (5)
 aspng general ASP.NET discussion forum (10)
 aspngbeta general ASP.NET technical discussion forum (30)
 aspngvs ASP.NET in Visual Studio.NET discussions (20)
 apngdata ADO.NET and data access discussions (15)
 aspngvb VB language discussions (10)
 aspngcs C# language discussions (10)
 aspngwebservices Web Services discussions (5)
 aspngconfig ASP.NET configuration discussions (5)
 aspngsecurity ASP.NET security discussions (5)
 aspngxml XML discussions (5)
 aspngmob ASP.NET mobile controls discussions (5)
 aspngarchitecture ASP.NET architecture discussions (5)
 aspngibuyspy discussions (10)

Click here to discover other discussion lists. []

Copyright 2000 Microsoft Corporation

Source Code
  Dim strFileName 
  strFileName = Server.MapPath("/demos/")

  Dim objFSO, objTS, strHTML
  Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
  Set objTS = objFSO.OpenTextFile(strFileName)
  strHTML = objTS.ReadAll
  Set objTS = Nothing
  Set objFSO = Nothing

  Dim objRegExp
  Set objRegExp = new RegExp

  'Assume strHTML contains the HTML with the <a href="<i>URL</i>"><i>URL Description</i></a>
  'We want to store into strText the HTML in strHTML, but with the HREF tags
  'changed to a more text-friendly <i>URL Description</i> [<i>URL</i>]
  objRegExp.IgnoreCase = True
  objRegExp.Global = True
  objRegExp.Pattern = "<a\s+href=""http://(.*?)"">\s*((\n|.)+?)\s*</a>"

  'Now, replace the HREF tags with our preferred format
  strText = objRegExp.Replace(strHTML, "$2 [http://$1]")

  Set objRegExp = Nothing

[Return to the Article] | [View the SubMatches demo]