RegExps in js

D

David

Hi all,

I have a function that produces a string within it with a root relative
path...

/mysite/images/

The problem is that this is being "seen" as a RegExp when processing it
further in the script. I really need this string to stay in this format. Is
there a way to make the script not see this as a RegExp?

Thanks, David
 
D

David

I have a function that produces a string within it with a root relative
path...

/mysite/images/
The problem is that this is being "seen" as a RegExp when processing it
further in the script. I really need this string to stay in this format.
Is there a way to make the script not see this as a RegExp?

Just in case more info is needed here is an example of how it is. One
function gets the var from an ASP query string. This function then contains
another function, named otherFunction() here, which prosesses this var.

function whatever(){
var theString='<%=Request.QueryString("cap")%>'
eval("otherFunction("+theString+")");
}

Hope this helps a bit.

David
 
I

Ivo

David said:
Just in case more info is needed here is an example of how it is. One
function gets the var from an ASP query string. This function then contains
another function, named otherFunction() here, which prosesses this var.

function whatever(){
var theString='<%=Request.QueryString("cap")%>'
eval("otherFunction("+theString+")");
}

Why are you using eval?

otherFunction( theString )

should really be enough. If you look closely to what you are passing the
eval, it *is* a RegExp! There are no quotes around theString, which is
needed to recognize an argument as a string. Here eval is used once more,
but this time with single quotes delimiting theString, and all inside the
double quotes:

eval("otherFunction( '"+theString+"' )");

hth
ivo
 
M

Martin Honnen

David wrote:

function whatever(){
var theString='<%=Request.QueryString("cap")%>'
eval("otherFunction("+theString+")");

Why can't you simply call
otherFunction(theString)
? That calls the function and passes in the string value. The only
problem seems to be that you call eval.
 
D

David

Why can't you simply call
otherFunction(theString)
? That calls the function and passes in the string value. The only problem
seems to be that you call eval.
 
D

David

function whatever(){
Why can't you simply call
otherFunction(theString)
? That calls the function and passes in the string value. The only problem
seems to be that you call eval.


Either way I do it, it still sees it as a RegExp.

function whatever(){
var theString='<%=Request.QueryString("cap")%>'
eval("otherFunction("+theString+")");
}

****************************
function whatever(){
var theString='<%=Request.QueryString("cap")%>'
otherFunction(theString);
}
 
D

David

Why are you using eval?
otherFunction( theString )

should really be enough. If you look closely to what you are passing the
eval, it *is* a RegExp! There are no quotes around theString, which is
needed to recognize an argument as a string. Here eval is used once more,
but this time with single quotes delimiting theString, and all inside the
double quotes:

eval("otherFunction( '"+theString+"' )");

hth
ivo


Wait, my bad.

Delimiting the args or eliminating the eval alltogether works.

Thanks guys :)

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top