Error: unterminated parenthetical in RegExp

G

gypsy3001

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
 
G

gypsy3001

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
 
L

Lee

(e-mail address removed) 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," "));


--
 

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,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top