[Javascript] OT: RegExp

Shawn Milo milo at linuxmail.org
Wed May 12 12:49:40 CDT 2004


I don't think it's off-topic -- it's still Javascript.

Here is the code:

         var someQuery = "select name, (select 'subselect', 2+2 as sum, 5*3 as product from my_table) from another_table where number = (select id_nro from third_table where birthdate is not null)"

         document.write(someQuery + '<br/>');

         someQuery = someQuery.replace(/\([^)]*\)/g, '');

         document.write(someQuery + '<br/>');


explanation of regex:

find a ( followed by anything that is not a ) for any number of characters (including zero),
followed by a ).  Replace the entire thing with an empty string.

The '(' and ')' are escaped '\(' and '\)'  because parenthesis have 
meaning in regexes.

Shawn 



More information about the Javascript mailing list