3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = '"hi (text here) and (other text)" come (again) and "(again)", right?'; echo preg_replace( '~(?:\G(?!^)|"(?=[^"]+"))[^"()]*(?:"(*SKIP)(*FAIL)|\K[()])~', '\\\$0', $str );

preferences:
42.72 ms | 1395 KiB | 5 Q