【发布时间】:2011-10-19 06:55:11
【问题描述】:
我正在尝试构建一个正则表达式,当它们之间有空格时将数字连接到字符串中,例如:
$string = "I want to go home 8890 7463 and then go to 58639 6312 the cinema"
正则表达式应该输出:
"I want to go home 88907463 and then go to 586396312 the cinema"
正则表达式可以是 python 或 php 语言。
谢谢!
【问题讨论】:
-
"(\d) (\d)",然后用"\1\2"替换? (无论如何,使用 Python 风格的正则表达式) -
@Thomas,不,不适用于
1 2 3,对于这种情况,您需要至少使用一次环视。 -
@tugaPT,像
foo123 5bar这样的字符串呢,也应该加入吗?
标签: php python regex replace preg-replace