2017-07-07 103 views
0

發現了一個角色,我想更換一個點後跟一個空格,後面跟着一個大寫字母,我嘗試這種模式通過   來替代它:保留通過的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

回答

1

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

'/\.\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

是的,這是完美的,謝謝。 –

相關問題