3v4l.org

run code in 500+ PHP versions simultaneously
<?php $string = 'whatever text including some $text between delimiters$ and...'; $string_replaced = preg_replace_callback('/\$[^$]*\$/', function($m) { return preg_replace('~\s+~u', ':', $m[0]); }, $string); echo $string_replaced;

preferences:
107.57 ms | 1539 KiB | 5 Q