$re = '/[\w\d]+\/(\d+)\/\d+\/\d+/m';
$str = 'R01/10000304603/000/00
2235011: R01/10000304604/000/00
2235021: R01/10000304605/000/00
2235031: R01/10000304606/000/00
2235601: R01/10000304607/000/00
2235611: R01/10000304608/000/00
2235621: R01/10000304610/000/00
2235631: R01/10000304611/000/00
';
$subst = "\t<\1>\n\t\t\2\t</\1>\n</\4>\n";
$result = preg_replace($re, $subst, $str);
echo "The result of the substitution is ".$result;
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php