<?php $r = '$1\1';echo preg_replace('~(B.*?S)~', str_replace(array('\\', '$'), array('\\\\', '\\$'), $r), "BOSS");
Standard input is empty
$1\1S
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!