Regular Expressions Buffer

thebraska

New Member
RegExpressions - backreferences<BR>I am trying to use backreferences to break down the parts of a URL. Microsoft has a pretty simple intro to this on their site(included below). ***MY QUESTION*** regards how to access the backreferences. I am a beginner, so forgive me if I am asking a really dumb question, but I am trying to use the following to without success --any ideas?:<BR><BR><BR><%<BR>dim strURL, re<BR>strURL = "Set">http://www.asp.com/one/two/asp.asp"<BR>Set re = New regexp<BR>re.Pattern = "(w+)://([^/:]+)(:d*)?([^# ]*)"<BR>re.Global = True<BR>re.IgnoreCase = True<BR>Response.Write re.$1<BR>Response.Write re.$2<BR>Response.Write re.$3<BR>Response.Write re.$4<BR>%><BR><BR>---------------------------------------------------------<BR>Exerpt from <BR>http://msdn.microsoft.com/scripting/default.htm?/scripting/vbScript/doc/vsobjRegExp.htm:<BR><BR>Another way that backreferences can be used is to break down a Universal Resource Indicator (URI) into its component parts. Assume that you want to break down the following URI down to the protocol (ftp, http, etc), the domain address, and the page/path:<BR><BR>http://msdn.microsoft.com:80/scripting/default.htm<BR>The following regular expressions provides that functionality. For JScript:<BR><BR>/(w+)://([^/:]+)(:d*)?([^# ]*)/<BR>For VBScript:<BR><BR>"(w+)://([^/:]+)(:d*)?([^# ]*)"<BR>The first parenthetical subexpression is designed to capture the protocol part of the web address. That subexpression matches any word that precedes a colon and two forward slashes. The second parenthetical subexpression captures the domain address part of the address. That subexpression matches any sequence of characters that does not include &#039^&#039, &#039/&#039, or &#039:&#039 characters. The third parenthetical subexpression captures a website port number, if one is specified. That subexpression matches zero or more digits following a colon. And finally, the fourth parenthetical subexpression captures the path andor page information specified by the web address. That subexpression matches one or more characters other than &#039#&#039 or the space character.<BR><BR>Applying the regular expression to the URI shown above, the submatches contain the following:<BR><BR>RegExp.$1 contains "http"<BR>RegExp.$2 contains "msdn.microsoft.com"<BR>RegExp.$3 contains ":80"<BR>RegExp.$4 contains "/scripting/default.htm"
 
Back
Top