<?php

$s = "1                #first                  (dog)";
echo preg_replace('~1\s*#~', ',$0', $s);