我需要一个用于替换字符“”的正则表达式。在“。”前后留一个空格,但前提是该点不属于数字(小数点):
示例:
test. of my country.brazil, should be 38.45
它应该返回:
test . of my country . brazil, should be 38.45
任何人都可以帮忙吗?
谢谢
答案 0 :(得分:1)
这应该可以解决问题:
<?php
$regex = '/([^0-9])\s?\.\s?([^0-9])/';
$string = 'test. of my country.brazil, should be 38.45';
$replace = '$1 . $2';
echo preg_replace($regex, $replace, $string);
//test . of my country . brazil, should be 38.45