<?php $s = "1 #first (dog)";echo preg_replace('~1\s*#~', ',$0', $s);
Standard input is empty
,1 #first (dog)
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!