有一篇很长的文章,我只想删除thousand separator,而不是逗号.
$str = "Last month's income is 1,022 yuan, not too bad.";
//=>Last month's income is 1022 yuan, not too bad.
preg_replace('#(\d)\,(\d)#i','???',$str);
Run Code Online (Sandbox Code Playgroud)
如何编写正则表达式模式?谢谢
如果简化的规则"匹配任何直接位于数字之间的逗号"对你来说已经足够了,那么
preg_replace('/(?<=\d),(?=\d)/','',$str);
Run Code Online (Sandbox Code Playgroud)
应该做.
您可以通过确保正好三位数来改进它:
preg_replace('/(?<=\d),(?=\d{3}\b)/','',$str);
Run Code Online (Sandbox Code Playgroud)