If I have a string of the form:
$text='remove1 (keep1) remove2 (keep2) remove3';
Using the response
https://stackoverflow.com/a/5293343/1154853
$re = '/[^()]*+(\((?:[^()]++|(?1))*\))[^()]*+/';
$text = preg_replace($re, '$1', $text);
I get
(keep1)(keep2)
If I want to go from
$text='remove1 {keep1} remove2 {keep2} remove3';
to
{keep1}{keep2}
that is I want to change the delimiters, how do I change the given regular expression? I tried all sorts of combinations of changing ( to { but I couldn't get it to work. I find these reg exp pretty tough!