[thelist] regex: replacing bracket characters

Hershel Robinson Hershel at GalleryRobinson.com
Wed Dec 10 08:54:53 CST 2003


> objRegExp = /()/g;
> objRegExp = /\(\)/g;

Those would match only the text '()'. Probably the second one actually. The
first is probably meaningless, depending on what language you are using.

You need either to use 2 expressions:

objRegExp = /\(/g;
objRegExp = /\)/g;

and execute each separately or use an option like:

objRegExp = /[\(\)]/g;

which may or may not work depending on what language you are using to
execute your regular expression. There are many and each implements them
differently.

Furthermore you need to be sure to replace the found text, as in:

objRegExp = s/[\(\)]//g;

Again, depending on the language.

HTH

Hershel



More information about the thelist mailing list