如何在PHP中删除数字而不是字母之间的逗号

时间:2013-05-08 05:43:54

标签: php

例如,我想将字符串There are 4,000 bugs, fix them!替换为There are 4000 bugs, fix them!

请注意删除第一个逗号,但保留第二个逗号。

3 个答案:

答案 0 :(得分:4)

preg_replace('/([0-9]),([0-9])/', '\\1\\2', 'There are 4,000 bugs, fix them!');

答案 1 :(得分:2)

试试这个正则表达式:

/(\d+)(,)(\d+)/$1$3/

只是为了防止在这里作为propper php:

preg_replace('/(\d+)(,)(\d+)/', '\\1\\3', $input_string);

答案 2 :(得分:0)

试试这个

$str = "There are 4,000 bugs, fix them!";
$a = preg_replace('#(?<=\d),(?=\d)#', '',  $str);
print_r($a);