p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

proasp_codeclinic thread: Regular expressions


Message #1 by "Sam Stauffacher" <sam@i...> on Thu, 7 Nov 2002 10:30:19
I am using regex in asp to extract a long list of names matched with a 
corresponding querystring ID
number from a remote webpage. So far I have 
had no problem extracting both items and iterating through both lists 
seperately. My
challenge is combining both extracted values into a single 
line as I iterate through the collection. Any suggestions on how to

iterate through two matches simultaneously?





<%@LANGUAGE="VBSCRIPT"
CODEPAGE="1252"%>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
function OpenWindow(theURL,winName,features)
{
window.open(theURL,winName,features);
}
</script>
</head>
<body>
<table width="500" border="0"
cellpadding="0" cellspacing="0">
<%
RefPage = "http://www.calteach.com/ctsearch/lowper_result.cfm?cty=43&"
Set objXMLHTTP
= Server.CreateObject("Microsoft.XMLHTTP")
objXMLHTTP.Open "GET", RefPage, False
objXMLHTTP.Send
RefPage =
objXMLHTTP.responseText
quote = chr(34)

Set objRegExpr = New regexp
objRegExpr.Global = True
objRegExpr.IgnoreCase =
True

objRegExpr.Pattern = "id=[0-9]{4}"
Set colMatches2 = objRegExpr.Execute(refpage)

objRegExpr.Pattern = "      <a
href=""e&"lowper_details.cfm\?
id=....""e&">"
RefPage = objRegExpr.Replace(refpage,( chr(253) ))
objRegExpr.Pattern =
"</a> </td>"
RefPage = objRegExpr.Replace(refpage,( chr(254) ))
objRegExpr.Pattern = chr(253) & "[^" & chr(254)
& "]*" & chr(254)


Set colMatches = objRegExpr.Execute(refpage)
For each bap in colMatches
'For each objMatch in
colMatches2

yup = (replace(bap.Value,"
", ""))
newd = (replace(yup, "", ""))
'erat = (replace(objMatch.Value, "id=",""))

response.write "<tr><td><font size='2' face='Verdana, Arial, Helvetica, 
sans-serif' onclick=""e&"OpenWindow
('http://www.calteach.com/ctsearch/lowper_details.cfm?id="&erat&_
"','','scrollbars=yes,width=500,height=400')""e&">" & newd &_
"</font></td></tr>"
'next
Next

Set colMatches = Nothing
Set objRegExpr = Nothing
%>
</table>
</body>
</html>

  Return to Index