Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why RegExp Problem ???

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi,

I have been having problems finding out why this regular expression is not working. The error points to the first line of the below chunk of code.

--------------------------------
StringToSearch = File.FileName
Set RegularExpressionObject = New RegExp

RegularExpressionObject.Pattern = ".exe"
RegularExpressionObject.IgnoreCase = True
RegularExpressionObject.Global = True

Set expressionmatch = RegularExpressionObject.Execute(StringToSearch)

If expressionmatch Then
Response.Redirect "failed.html"
end if
 
File.FileName gets a File's name and converts it into a like string
 
is that the line that the error points to? if so, perhaps it's not your regex that's bad, but something with getting that filename?
 
theres nothing wrong with the File.FileName coz if I do a response.write on it. It'll show
 
oh, i thought you said that was the line the error was pointing to.

so which line is the error pointing to, and what is the error?
 
The error for some reason points to that line and if I was to change File.FileName to something like "fhdsjkhfjkhf.exe" an error will show about the RegularExpressionObject is undefined ???
 
you're looking for everything that ends in .exe?

you'll need to change the regexp pattern to look like
re.pattern = "\.exe"

the . is a wildcard char to mean anything, so .exe will always give you more than just the executables.

a better way to do it would be to limit the search to the end of the string. ie: re.pattern = "(\.exe)$"

so only files ending in .exe would get found by that pattern. you might want to check that, though, since I've been using perl the last couple months, and my syntax might be a bit off :)

hth leo

------------
Leo Mendoza
lmendoza@students.depaul.edu
 
Hello, md10943.

expressionmatch is a collection and will not stand ready for If Then test criteria. Hence, the revision would be:

If expressionmatch.count Then
or
If expressionmatch.count<>0 Then

regards - tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top