regexp在句点后添加空格,但是当句点代表小数或字母缩写时不添加空格吗? [英] regexp add space after period but not when period represents a decimal or letter abbreviation?

查看:110
本文介绍了regexp在句点后添加空格,但是当句点代表小数或字母缩写时不添加空格吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以一种简单的方式使用php regexp,是否可以修改字符串以在单词后面的句点之后添加一个空格,而不是在前面和后面跟着一个数字(例如1.00)的后面添加空格?我还需要它忽略单个字母的缩写,例如NY

Using php regexp in a simple way, is it possible to modify a string to add a space after periods that follow words but not after a period that is preceded and followed by a number such as 1.00? I also need it to ignore single letter abbreviations such as 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.

这应该允许在该字符串中包含多个实例。 。

This should allow for multiple instances within the string of course...

推荐答案

$text = preg_replace('/(\.)([[:alpha:]]{2,})/', '$1 $2', $text);

这篇关于regexp在句点后添加空格,但是当句点代表小数或字母缩写时不添加空格吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆