Oliver
Oliver

Reputation: 23510

How to add a space after a point?

I'd like to add a space after any point found with an alphabetic or numeric character just after it (no space found), assuming the next character after the point is not an end of line (cr, lf, ...) character.

preg_replace "/.[a-z0-9]{1}/" with "/. [a-z0-9]/i"

How may I do this in PHP ?

Upvotes: 0

Views: 329

Answers (2)

DarkDevine
DarkDevine

Reputation: 1047

You already posted the almost correct answer

$text = preg_replace( '#\.([A-Za-z0-9])#', '. $1', $text );

should do the trick

Upvotes: 2

Felix Kling
Felix Kling

Reputation: 816482

You can use a positive lookahead:

$str = preg_replace("/\.(?=[a-z\d])/i", ". ", $str);

DEMO

Upvotes: 5

Related Questions