I have to do a site redirect through script for about 10 different URLS all containing the string "enterpriseloyalty". I'm trying to write some RegEx to find out if the URL has this in it. To do so, I'm using a function I found on another question here (using classic asp for regular expression). The problem is that nothing is returning when I test it on the site "http://enterpriseloyaltyjournal.ca/".
I've tested the regex in both http://gskinner.com/RegExr/ and http://www.pagecolumn.com/tool/regtest.htm with matching results of the regex "enterpriseloyalty[A-Za-z]*(?=.{1,1})" working, matching "enterpriseloyaltyjournal" in the URL string. But on the site, "Response.Write("Results: " & result.Submatches(0))" returns nothing at all. And to be honest, I don't know if I am expecting a result of the matching string or what, but there's just nothing at all returned.
When I just do an If InStr(Request.ServerVariables("SERVER_NAME"),"enterpriseloyaltyjournal.ca") > 0 Then
statement, it comes back true. My code is below. Any help is greatly appreciated.
Function RegExResults(strTarget, strPattern)
Set regEx = New RegExp
regEx.Pattern = strPattern
regEx.Global = true
Set RegExResults = regEx.Execute(strTarget)
Set regEx = Nothing
End Function
'Pass the original string and pattern into the function and get a collection object back'
Set arrResults = RegExResults(Request.ServerVariables("SERVER_NAME"), "enterpriseloyalty[A-Za-z]*(?=\.{1,1})")
'In your pattern the answer is the first group, so all you need is'
For each result in arrResults
Response.Write("Results: " & result.Submatches(0))
Next
EDIT
I'm also trying the following with no results:
Regex.IgnoreCase = True
Regex.Pattern = "enterpriseloyalty[A-Za-z]*(?=\.{1,1})"
Response.Write("Results:" & Regex.Test(Request.ServerVariables("SERVER_NAME")))
Also, when I say "no results", I mean nothing at all is returned. Not even the "Results:" portion. Though I'm not getting any type of error.
SOLVED
Changed the above code to look like:
Dim regex
Set regex = New RegExp
regex.IgnoreCase = True
regex.Pattern = "enterpriseloyalty[A-Za-z]*(?=\.{1,1})"
Response.Write("Results:" & regex.Test(Request.ServerVariables("SERVER_NAME")))
And it worked just fine.