By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,719 Members | 1,278 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,719 IT Pros & Developers. It's quick & easy.

How to insert a space before capital letters in a string?

P: n/a
Hi, I am trying to insert a space before all capital letters in a string
except the first occurrence. For example:

FirstSecondThird

would become

First Second Third

Is there a regular expression or short function that can do this?
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Jeff wrote:
Hi, I am trying to insert a space before all capital letters in a string
except the first occurrence. For example:

FirstSecondThird

would become

First Second Third

Is there a regular expression or short function that can do this?


Something along the lines of this should help:

$string = 'FirstSecondThird';
$string = preg_replace('/(\w+)([A-Z])/U', '\\1 \\2', $string);
print $string;

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #2

P: n/a
Thanks, works great!
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.