PDA

View Full Version : replace function and "("



Jas
06-23-2007, 10:42 PM
I am having some trouble with the replace() function in JS.
I need to replace all of these: (center]
with these: <center>
and these: [center)
with these </center>
etc.
I can change one, but I need to change them all in a string that the user types in (it's for a forum, obviously).

Thx.

Trinithis
06-24-2007, 01:29 AM
myStr.replace(/\(center\]/g, "<center>").replace(/\[center\)/g, "</center>");
For case insensitivity as well:

myStr.replace(/\(center\]/gi, "<center>").replace(/\[center\)/gi, "</center>");