Kristian Rafteseth
Kristian Rafteseth

Reputation: 2032

Insert a dot then a space after a lowercase letter which is immediately followed by an uppercase letter

I'm trying to accomplish the following:

search for a lowercase letter followed by uppercase letter. replace this with the lowercase letter, followed by '. ', followed by the uppercase letter.

example:

helloAre you there

should become:

hello. Are you there

Upvotes: 2

Views: 186

Answers (3)

agent-j
agent-j

Reputation: 27913

Inserts a dot-space . between the lower and upper-case letters.

preg_replace('/(?<=[a-z])(?=[A-Z])/', '. ', $str);

To prevent iP, use this:

preg_replace('/(?!iP)([a-z])(?=[A-Z])/', '$1. ', $str);

Upvotes: 3

borrible
borrible

Reputation: 17356

If $text is the original text you could use

$text = preg_replace('/([a-z])([A-Z])/', '\1. \2', $text);

Upvotes: 0

user142162
user142162

Reputation:

preg_replace('/([a-z])([A-Z])/', '$1. $2', $str);

Upvotes: 7

Related Questions