$re = '/(((?:[+\-\/*]6+|6+[+\-\/*]|([^6]|\b)6{1,2}(?3)|(?3)6{6,}(?3)|[0-57-9]6+|6+[0-57-9])(*SKIP)(*F))|6)/m';
$str = '66
老铁666这类的, 6666
三到五个六66666
5666有其他数字不替换
6665
566665
666666
66
+66
666-
';
$subst = "六";
$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