$re = '@\d{3}\.\d*$|(?<!^)(?=(?:\d{3})+(?:\.|$))@m';
$str = '1
12
123
1234
12345
123456
1234567
12345678
123456789
12345678.1
12345678.12
12345678.123
12345678.1234
12345678.12345
12345678.123456
12345678.1234567
12345678.12345678
12345678.12345689
12345678.123456890
';
$subst = ",$0";
$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