保留通过的preg_replace

问题描述:

发现了一个角色,我想更换一个点后跟一个空格,后面跟着一个大写字母,我尝试这种模式通过   来替代它:保留通过的preg_replace

preg_replace('/\. [A-Z]/', '.    'With marriage came a move to the beautiful Birmingham, Alabama area. Diving in head first.'); 

它的工作,但我失去的d首先潜水。

我该如何保留它?

+1

' '/ \ \ S + /。(= [A-Z])'' –

+0

的preg_replace( '/ \([A-Z])/。',$ S”       $ 1' ); $ s是你的字符串 – user10089632

把信匹配模式到非消耗前瞻:

'/\.\s+(?=[A-Z])/' 

\s+将匹配1个或多个空格(或者,如果你不希望这样,保持经常的空间)和(?=[A-Z])使得发动机要求在字符串中的当前位置之后出现一个大写的ASCII字母。

查看PHP demo印刷With marriage came a move to the beautiful Birmingham, Alabama area.   Diving in head first.

+0

是的,这是完美的,谢谢。 –