我如何调节正则表达式以检查匹配项中是否存在字符串以不重复它
这是我想要的一个例子(错误代码)
$string = "1234";
$replacement = "/$1(5?)/"; // this should check if "5" is in $string, if not then add it with $1
preg_replace('/(.*)/', $replacement, $string);
有什么好的建议$replacement
?
我只想使用preg_replace
一行代码没有其他功能