这是我目前用于清理句子的正则表达式,当人们写出以下内容时:
它将被自动转换为:Hello.I'm Andres,right?
当字符串中有数字时,问题就出现了。例如:Hello. I'm Andres, right?
...将被转换为:I have 40.381,32 dollars.
我的当前代码:I have 40. 381, 32 dollars.
echo preg_replace( '/[!?,.](?![!?,.\s])/', '$0 ', 'Hello my friend.There should be a space after sentence periods and commas, but that should not apply to 40.381,32 numbers.');
问题:当,.字符在数字之间时,如何避免这些规则被应用?谢谢!
preg_*
函数使用PCRE,支持向后查找。这是有关前后查找的PHP手册。 - Wiseguy