sandy1028 Posted November 2, 2011 Share Posted November 2, 2011 In the text, It will eventually go away.Once the carriers merge, the combined airline, will operate as Southwest. It has its logo and colors. 2.3 AirTran brand will no longer be used. In the above text, how to replace "." with ". " and not in 2.3. how to add space after "." only if it has alphabets and not to replace after numeric characters. Quote Link to comment https://forums.phpfreaks.com/topic/250274-replace-in-the-text/ Share on other sites More sharing options...
ocpaul20 Posted November 2, 2011 Share Posted November 2, 2011 some kind of pattern matching I assume but I am terrible at that. I tend to do it the long way with a for loop on the string rather than get my head around all the pattern matching syntax. Quote Link to comment https://forums.phpfreaks.com/topic/250274-replace-in-the-text/#findComment-1284174 Share on other sites More sharing options...
jcbones Posted November 2, 2011 Share Posted November 2, 2011 <?php $str = 'It will eventually go away.Once the carriers merge, the combined airline, will operate as Southwest. It has its logo and colors. 2.3 AirTran brand will no longer be used. '; $patt = '~(\.)([^\d\s])~'; //select a period that is NOT followed by a numerical digit or a space (capturing the space in the 1st group, and the alpha character in the second group). $str = preg_replace($patt,'$1 $2',$str); //replace the pattern with the 1st capture and the 2nd capture separated by a space. echo $str; ?> Quote Link to comment https://forums.phpfreaks.com/topic/250274-replace-in-the-text/#findComment-1284375 Share on other sites More sharing options...
xyph Posted November 2, 2011 Share Posted November 2, 2011 If it has to be a full stop, why would you capture it? Quote Link to comment https://forums.phpfreaks.com/topic/250274-replace-in-the-text/#findComment-1284376 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.