HaBo HaBo - 1 year ago 166
Javascript Question

jQuery - Replace all parentheses in a string

I tried this:

mystring= mystring.replace(/"/g, "").replace(/'/g, "").replace("(", "").replace(")", "");

It works for all double and single quotes but for parentheses, this only replaces the first parenthesis in the string.

How can I make it work to replace all parentheses in the string using JavaScript? Or replace all special characters in a string?

Answer Source

Try the following:

mystring= mystring.replace(/"/g, "").replace(/'/g, "").replace(/\(|\)/g, "");

A little bit of REGEX to grab those pesky parentheses.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download