- preg_replace: documentation ( source)
<?php
$str = '"hi (text here) and (other text)" come (again) and "(again)", right?';
echo preg_replace(
'~(?:\G(?!^)|"(?=[^"]+"))[^"()]*(?:"(*SKIP)(*FAIL)|\K[()])~',
'\\\$0',
$str
);