Php regexp是否在逗号后添加空格,但在逗号为千分位时不添加空格?

Php regexp是否在逗号后添加空格,但在逗号为千分位时不添加空格?,php,regex,punctuation,Php,Regex,Punctuation,以一种简单的方式使用php regexp,是否可以修改字符串以在逗号和紧跟单词的句点后添加空格,而不是在逗号或后跟数字(如1000.00)的句点后添加空格 String,looks like this with an amount of 1,000.00 需要更改为 String, looks like this with an amount of 1,000.00 当然,这应该允许多个实例。。。这是我现在使用的,但它导致数字返回1000。00 $punctuation = ',.;:';

以一种简单的方式使用php regexp,是否可以修改字符串以在逗号和紧跟单词的句点后添加空格,而不是在逗号或后跟数字(如1000.00)的句点后添加空格

String,looks like this with an amount of 1,000.00
需要更改为

String, looks like this with an amount of 1,000.00
当然,这应该允许多个实例。。。这是我现在使用的,但它导致数字返回1000。00

$punctuation = ',.;:';
$string = preg_replace('/(['.$punctuation.'])[\s]*/', '\1 ', $string);

您可以替换
”/(?我正在搜索这个正则表达式

这篇文章真的帮助了我,我改进了Qtax提出的解决方案

这是我的:

$ponctuations = array(','=>', ','\.'=>'. ',';'=>'; ',':'=>': ');
foreach($ponctuations as $ponctuation => $replace){
    $string = preg_replace('/(?<!\d)'.$ponctuation.'(?!\s)|'.$ponctuation.'(?!(\d|\s))/', $replace, $string);
}
$ponctuations=array(“,”=>“,”,“\.=>”,“;”=>“;”,“:”=>“:”);
foreach($PONCUTIONS as$PONCUTION=>$replace){

$string=preg_replace('/(?虽然这是一个很老的问题,但我一直在寻找相同的问题,在理解给出的解决方案后,我有了不同的答案

该正则表达式不检查逗号前的字符,而是检查逗号后的字符,因此可以将其限制为字母字符。此外,这也不会创建逗号后有两个空格的字符串

$punctuation = ',.;:';
$string = preg_replace("/([$punctuation])([a-z])/i",'\1 \2', $string);

可以检查测试脚本。

这非常接近我要查找的内容…在我提供的代码示例中,您如何修改它以使用我的$标点符号变量?谢谢
$str=preg\u replace('/(?)?
$punctuation = ',.;:';
$string = preg_replace("/([$punctuation])([a-z])/i",'\1 \2', $string);