Grabbing the Text Between Bold Tags

This demo illustrates how to use regular expressions to grab the contents between bold tags in an HTML document. The HTML page we're accessing has the following contents:

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE>This contains a lot of bold tags!</TITLE>
</HEAD>
<BODY>

Some <b>people think</b> that <b>BOLD</B> tags are annoying.
I say <b><i>Posh</i></b> to that!  <B>POSH!</B>
Yes, I am one who says "<b>posh</b>" quite <b>regularly</B>.
<B>VERY REGULARLY!</B>  Just watch.
<p>
POSH.  <B>POSH POSH POSH!</B>

</BODY>
</HTML>

The source code of the ASP on this page is as follows:

<%
Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

Dim objFile
Set objFile = objFSO.OpenTextFile(Server.MapPath("/demos/ExampleHTMLBOLD.html"))

Dim strContents
strContents = objFile.ReadAll

objFile.Close
Set objFile = Nothing
Set objFSO = Nothing

Dim objRegExp
Set objRegExp = New RegExp

Dim strHTML, strMatch
strMatch = "<b>(.*?)<\/b>"

objRegExp.Pattern = strMatch
objRegExp.IgnoreCase = True
objRegExp.Global = True

Dim objMatches, objMatch
Set objMatches = objRegExp.Execute(strContents)

Response.Write "The following bold tags exist:<br>"
For Each objMatch in objMatches
  Response.Write objMatch.Value & "<BR>"
Next

Set objRegExp = Nothing
%>


The Resulting Output

The following bold tags exist:
people think
BOLD
Posh
POSH!
posh
regularly
VERY REGULARLY!
POSH POSH POSH!


[Return to the Article] | [View the TITLE Regular Expressions demo]