I’m looking for a Perl regex that will capitalize any character which is preceded by whitespace (or the first char in the string).
I’m pretty sure there is a simple way to do this, but I don’t have my Perl book handy and I don’t do this often enough that I’ve memorized it…
Depending on your exact problem, this could be more complicated than you think and a simple regex might not work. Have you thought about capitalization inside the word? What if the word starts with punctuation like ‘…Word’? Are there any exceptions? What about international characters?
It might be better to use a CPAN module like Text::Autoformat or Text::Capitalize where these problems have already been solved.
It sounds like Text::Autoformat might be more ‘standard’ and I would try that first. Its written by Damian. But Text::Capitalize does a few things that Text::Autoformat doesn’t. Here is a comparison.
You can also check out the Perl Cookbook for recipie 1.14 (page 31) on how to use regexps to properly capitalize a title or headline.