Is it possible to make a rule that can simultaneously remove any parts of the string enclosed with [] () and {} in one go, only leaving any part of it?
For example, if I have a string like this:
// Input
$string = 'my(apple)[banana][carrot(orange)]food[supply]';
// Output
$string = 'myfood';
I know how to select parts of a string that is enclosed with brackets, but in this case I want to select any parts that isn't enclosed instead.
Here's my current regex where I'm stuck, which I can select the enclosed characters:
\[.*?\]|\(.*?\)|\{.*?\}
This is work around to achieve this,
$string = 'my(apple)[banana][carrot(orange)]food[supply]{test}';
echo preg_replace('/{(.*?)}|\[.*?\]|\([^)]+\)/","",$string);
Here is working demo.
I found out the answer:
$var = 'my(apple)[banana][carrot(orange)]food[supply]';
echo preg_replace('/\[.*?\]|\(.*?\)|\{.*?\}/', '', $var);