in reply to Capitalization Case Help!
Since that uses zero-width look-behind, which has to involve a fixed number of characters to match, you'd have to add another separate regex to handle the case of "Mac..." (that is, just adding "a?" to the last regex above would cause a run-time error).sub cap { local $_ = shift || ''; s/\b(\w\S*)/\u\L$1/g; s/(?<=\bO')(\w)/\u$1/g; s/(?<=\bMc)(\w)/ \u$1/g; return $_; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Capitalization Case Help!
by AnomalousMonk (Archbishop) on Sep 16, 2010 at 03:22 UTC |