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!

RegExp object help

Status
Not open for further replies.

motte

Programmer
May 31, 2001
155
US
I ran across a problem this weekend working with the regexp object. Since I do most of my programming in perl, reg expressions are not new to me. But ASP gave me some problems.

I had a string...actually a path on my drive...
example:
e:\mike.com\templates\foo.asp
This became my string:

I was looking for a pattern in the string:
pattern="e:\mike.com\templates\"

I wanted to replace that pattern with nothing, so I could get foo.asp.

I was getting some error when trying to use .replace...

I had something like this:
*****************************************
dim re, string
set re=new regexp
string="e:\mike.com\templates\foo.asp"
re.pattern="e:\mike.com\templates\"
if re.test(string) then
re.replace(string, "")
end if
*****************************************

I was getting some error that said the parenthesis shouldn't be used for replace...So I got rid of them, though all documentation told me to have them. Then I tried without the (). It said replace was not a valid method, or something like that. Does anyone know what the deal was?

I actually decided to go a different way and create a filesystemobject to grab the file's name. But I don't understand why the pattern replace didn't work. I am using IE 6.0 now.

I'd love to hear if anyone knows the deal behind this.

Mike
 
trying using call re.replace(string, "")
 
sauerc,

Actually, now looking at it and trying it out, I know what I did wrong. My pattern "e:\mike.com\templates\" is flawed. The backslashes and dot need to be escaped so they actually represent backslashes and dots...pattern should be "e:\\mike\.com\\templates\\"...i forgot since i thought i was dealing with just a string. with this set up, it works like a charm. Thanks for your advice though. fyi, using 'call' would work but when i want to reveal the end result, it fails since i didn't set the result to anything:

call re.replace(string,"") 'will not change string.
string=call re.replace(string,"") 'this would change string but does not work since you can't set a variable to a 'call'.

in order to work, it'd have to be this way.
string=re.replace(string,"")

Now I know.

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top