Error: unterminated parenthetical in RegExp

Discussion in 'Javascript' started by gypsy3001@yahoo.com, Feb 2, 2007.

  1. Guest

    Today, I was trying to construct a regular express in JavaScript. But
    I kept getting the "Error: unterminated parenthetical" message.

    I want to do something like this:

    keyCombo = ":(";
    pattern = new RegExp (keyCombo);
    str = string.replace (pattern, "frown");

    So, first thing I fixed is ":\(" . . . But I still get the same error!
    I've also tried ":\\\\(". And that didn't work. Please help and give
    me a hint. Thanks.

    Chieh
    --
    GearHack - http://www.GearHack.com/
     
    , Feb 2, 2007
    #1
    1. Advertising

  2. Guest

    > I want to do something like this:
    >
    > keyCombo = ":(";
    > pattern = new RegExp (keyCombo);
    > str = string.replace (pattern, "frown");
    >


    Ok, I figured it out. It has to be surrounded by brackets to be
    recognized as a character:

    ":[\(]"

    Now I'm having another problem. "<3" isn't being recognized. It
    doesn't error out. But none of the permutations work: "\<3", "[<]3",
    and "[\<]3".

    Quite weird . . . . there are so many exceptions to regular
    expression. *sigh*

    Chieh
    --
    GearHack - http://www.GearHack.com/
     
    , Feb 3, 2007
    #2
    1. Advertising

  3. Lee Guest

    said:
    >
    >> I want to do something like this:
    >>
    >> keyCombo = ":(";
    >> pattern = new RegExp (keyCombo);
    >> str = string.replace (pattern, "frown");
    >>

    >
    >Ok, I figured it out. It has to be surrounded by brackets to be
    >recognized as a character:
    >
    >":[\(]"
    >
    >Now I'm having another problem. "<3" isn't being recognized. It
    >doesn't error out. But none of the permutations work: "\<3", "[<]3",
    >and "[\<]3".
    >
    >Quite weird . . . . there are so many exceptions to regular
    >expression. *sigh*


    Why are you going through strings to get a RegExp?
    Try RegExp literals:

    pattern=/:\(/;

    What do you mean by "none of the permutations *work*"?

    var pattern=/<3/;
    alert("abc<3def".replace(pattern," "));


    --
     
    Lee, Feb 3, 2007
    #3
    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. John Salerno
    Replies:
    3
    Views:
    573
    John Salerno
    Jun 5, 2008
  2. Joao Silva
    Replies:
    16
    Views:
    409
    7stud --
    Aug 21, 2009
  3. Replies:
    3
    Views:
    256
    Douglas Crockford
    Dec 18, 2004
  4. William
    Replies:
    18
    Views:
    429
    Thomas 'PointedEars' Lahn
    Jan 25, 2006
  5. totalstranger
    Replies:
    0
    Views:
    212
    totalstranger
    Mar 2, 2007
Loading...

Share This Page