VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This asp page contains a function which uses Regular Expression patterns to find html strings. The

by Hugh Musser (8 Submissions)
Category: Active Server Pages
Compatability: ASP (Active Server Pages)
Difficulty: Unknown Difficulty
Originally Published: Thu 19th September 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This asp page contains a function which uses Regular Expression patterns to find html strings. The tags can then be replaced with a user

Rate This asp page contains a function which uses Regular Expression patterns to find html strings. The



<%
ExampleHTML= "" & _
        "<table width='100%'>" & vbnewline & _
        "  <tr>" & vbnewline & _
        "    <td rowSpan='99'><font size='2' face='Arial'><img src='techtemp/spacer2.gif' width='1' height='1'></font></td>" & vbnewline & _
        "    <td class='textcolor1' colSpan='2'><font size='2' face='Arial' color='#FFFFFF'><a href='http://example.com/aboutUs/0,289153,sid8,00.html' style='color: #FFFFFF'>About" & vbnewline & _
        "      Us</a>&nbsp;|&nbsp; <a href='http://example.com/buyersGuideForVendors/0,289879,sid8,00.html' style='color: #FFFFFF'>For" & vbnewline & _
        "      VB Vendors</a>&nbsp;|&nbsp; <a href='http://example.com/ffdc/0,289198,sid8,00.html' style='color: #FFFFFF'>For" & vbnewline & _
        "      Business Stuff</a>&nbsp;|&nbsp; <a href='http://example.com/stuff/0,289747,sid8,00.html' style='color: #FFFFFF'>Garden" & vbnewline & _
        "      Center Contacts</a></font></td>"

response.write "             Example HTML INPUT STRING    <br><br>"

response.write "<pre>" & Server.HTMLEncode(ExampleHTML) & "</pre>"

ExampleHTML=ReplaceSpecial(1, ExampleHTML, "<A(.*?)>", "########") '<<<=== function usage

response.write "<br><br>    Example HTML after anchor tags are replaced with '########'<br><br>"

response.write "<pre>" & Server.HTMLEncode(ExampleHTML) & "</pre>"




Function ReplaceSpecial(Strt, strng, patrn, RplcWith)
' Strt is position in string to start searching for pattern
' strng is input html string
' patrn is the search pattern string
' RplcWith is string used to replace found patterns
   Dim regEx, Match, Matches, cnt
   Set regEx = New RegExp 
   regEx.Pattern = patrn: regEx.IgnoreCase = True 
   regEx.Global = True
   Set Matches = regEx.Execute(strng)
   cnt=matches.count-1
   for i = cnt to 0 step -1
    if matches(i).FirstIndex >= strt then
strng=left(strng, matches(i).FirstIndex -0) & RplcWith & right(strng, len(strng)-(matches(i).FirstIndex + len(matches(i).value) - 0)) 
end if
   next
   ReplaceSpecial = strng
   set regEx=nothing
End Function
%>

Download this snippet    Add to My Saved Code

This asp page contains a function which uses Regular Expression patterns to find html strings. The Comments

No comments have been posted about This asp page contains a function which uses Regular Expression patterns to find html strings. The . Why not be the first to post a comment about This asp page contains a function which uses Regular Expression patterns to find html strings. The .

Post your comment

Subject:
Message:
0/1000 characters