View Single Post
Old 09-22-2014, 11:18 AM   #3
Tex2002ans
Wizard
Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.
 
Posts: 2,306
Karma: 13057279
Join Date: Jul 2012
Device: Kobo Forma, Nook
I tend to just use a general purpose regex to go from ALL CAPS -> Title Case. NEVER press "Replace All" when using this, only replace one-by-one.

I initially used this one (I probably gathered it from the forums here a long time ago):

Search: (\b)([A-Z])([A-Z]+)
Replace: \1\2\L\3

What this says in English is:

(RED) Grab the word boundary. More info can be found here: http://www.regular-expressions.info/wordboundaries.html
(BLUE) Grab the first capital letter A through Z and stick it in \2
(GREEN) Grab all the rest of the capital A through Zs in a row, and stick it in \3.

(RED) Replace with the word boundary, (BLUE) place the first capital letter, (GREEN) and change all of the UPPER CASE letters in \3 into their lowercase versions.

Recently though, I upgraded to this version:

Search: (\b)([\p{Lu}])([\p{Lu}]+)
Replace: \1\2\L\3

It looks a little scarier, but it does the same exact thing except it can handle UPPERCASE/lowercase versions of unicode letters.

Be careful, cases where this regex "fails" is getting hits on words with Roman Numerals ("World War II"). Also, in Title Case, words like "to", "from", "in", etc. etc. shouldn't begin with a capital letter, so I fix those manually as I come across them.

Last edited by Tex2002ans; 09-22-2014 at 11:21 AM.
Tex2002ans is offline   Reply With Quote