Reputation: 1807
I need to know if there is any way I can do the following using regular expressions (or otherwise) in PHP
aaBaa BBB -> aa Baa BBB
ie, I want to introduce a space before a capital letter only if a Capital letter occurs before and after a small letter.
The best I could come up with was something like this
$string = preg_replace('/(\w+)([A-Z])/U', '\\1 \\2', $string);
but that would only give me something like
aaBaa BBB -> aa Baa B B B
Thanks in advance.
Upvotes: 0
Views: 985
Reputation: 3181
Try this:
preg_replace('|([a-z])([A-Z])([a-z])|', '$1 $2$3', $txt);
Upvotes: 2