Oracle 12cR1 - I have a web based application I am writing. I have the need to process a string and remove open/close parentheses and all text within. For example, if my input is
This is a (bad) sample, (my) friend
the output should be
This is a sample, friend
I have this working in Javascript. I need it to work in BOTH javascript and Oracle SQL. The code in Javascript is
var s2 = s1.replace(/\([^()]*\)/g, '');
When I try to convert this to Oracle SQL, nothing happens, aka my output is exactly the same as my input...
select regexp_replace('This is a (bad) sample','/\([^()]*\)/g', '') from dual;
In searching, someone posted a different regexp expression, which I tried. Again, no change in the output.
select regexp_replace('This is a (bad) sample','(?<=\()[\d.]+(?=\))', '') from dual;
IDEALLY, what I would like is a regular expression that also handles nested parentheses, deleting the entire phrase.
This is a ((really) bad) example
should return
This is a example
For nested parentheses, the JavaScript expression matches on the inner most set of parentheses, so I just have to run my code twice, which works.
So in summary, what is an Oracle SQL statement that takes a string, and deletes (ideally nested) parentheses and all text within the parentheses? Note that there may be multiple sets of parentheses (not necessarily nested) so I need it to remove each occurrence of parentheses.