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:
25.25 ms | 404 KiB | 5 Q