RegExps in js

Discussion in 'Javascript' started by David, Jul 12, 2005.

  1. David

    David Guest

    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
     
    David, Jul 12, 2005
    #1
    1. Advertising

  2. David

    David Guest

    > 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
     
    David, Jul 12, 2005
    #2
    1. Advertising

  3. David

    Ivo Guest

    "David" <> wrote
    > > 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+")");
    > }


    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
     
    Ivo, Jul 12, 2005
    #3
  4. 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.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jul 12, 2005
    #4
  5. David

    David Guest


    >> 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.
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/
     
    David, Jul 12, 2005
    #5
  6. David

    David Guest

    >> 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.
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/



    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);
    }
     
    David, Jul 12, 2005
    #6
  7. David

    David Guest

    > 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
     
    David, Jul 12, 2005
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fredrik Ramsberg

    Optimisation of regexps in Perl?

    Fredrik Ramsberg, Oct 14, 2003, in forum: Perl
    Replies:
    2
    Views:
    474
    Fredrik Ramsberg
    Oct 15, 2003
  2. Replies:
    4
    Views:
    572
  3. Spartanicus

    Help with Regexps wanted

    Spartanicus, Oct 21, 2004, in forum: HTML
    Replies:
    4
    Views:
    462
    William Park
    Oct 25, 2004
  4. Klaus Alexander Seistrup

    Expanding regexps

    Klaus Alexander Seistrup, Oct 28, 2003, in forum: Python
    Replies:
    5
    Views:
    390
    Klaus Alexander Seistrup
    Oct 29, 2003
  5. Kirk Strauser

    Problems with regexps

    Kirk Strauser, Nov 7, 2003, in forum: Python
    Replies:
    6
    Views:
    314
    Edward K. Ream
    Nov 8, 2003
Loading...

Share This Page