Php regexp在句点后添加空格,但在句点表示十进制或字母缩写时不添加空格?
以一种简单的方式使用php regexp,是否可以修改字符串以在单词后面的句点之后添加空格,而不是在前面和后面都是数字(如1.00)的句点之后添加空格?我还需要它忽略单字母缩写,例如N.YPhp regexp在句点后添加空格,但在句点表示十进制或字母缩写时不添加空格?,php,punctuation,abbreviation,Php,Punctuation,Abbreviation,以一种简单的方式使用php regexp,是否可以修改字符串以在单词后面的句点之后添加空格,而不是在前面和后面都是数字(如1.00)的句点之后添加空格?我还需要它忽略单字母缩写,例如N.Y String.Looks like this.With an amount of 1.00 and references N.Y. 需要更改为 String. Looks like this. With an amount of 1.00 and references N.Y. 这应该允许字符串中有多个实
String.Looks like this.With an amount of 1.00 and references N.Y.
需要更改为
String. Looks like this. With an amount of 1.00 and references N.Y.
这应该允许字符串中有多个实例。当然…您可以使用此正则表达式:
$text = preg_replace('/(\.)([[:alpha:]]{2,})/', '$1 $2', $text);
/((?<=[A-Za-z0-9])\.(?=[A-Za-z]{2})|(?<=[A-Za-z]{2})\.(?=[A-Za-z0-9]))/
输出:
"String. Looks like this. With an amount of 1.00 and references N.Y. Mr. NoOne. 30% replaced. no 50. Don't know."
"String. Looks like this. With an amount of 1.00 and references N.Y. Mr. NoOne. 30% replaced. no 50. Don't know."