ごめ、

preg_replace("/>>(\d{1|2|3|4})+/","<a href=\"#log\\1\">>>\\1</a>",$str);  ね