View Single Post
Old 12-31-2012, 11:36 AM   #1
Turtle91
Guru
Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.
 
Turtle91's Avatar
 
Posts: 669
Karma: 3807234
Join Date: Dec 2012
Location: Shannon, Ireland today
Device: iPhone 5/iPad 1&2/Surface Pro/Kindle PW
Regex for Title Case or Sentence case?

Hi,

I've found and used (successfully) a regex for UPPERCASE/LOWERCASE using the \U \u \L \l \E markers.

Does anyone know of a way to use regex to transform a selection to sentence case or title case?

I'm trying to make transformation from ALL CAPS at the beginning of sentences (first paragraph) or in headers a little more automated. Sigil makes it very easy to manually change a highlighted range of text, but I was hoping for something I can put in the "replace" portion of the Find/Replace.

Ideally there would be something like \S or \T. e.g.:

Find: (<p class="first">)([[:upper:] \?!'-\.]{2,})([a-z]|</p>)
(selects all uppercase letters until it finds a lowercase letter OR the end of paragraph)

Replace: \1\T\2\E\3 (for Title Case)
Replace: \1\S\2\E\3 (for Sentence case)



I was trying this for sentence case - and it "seems" to work - but it changes the whole document; which is good if you are fixing grammar...

Find: ([\.|?|!])(\s*)(["|“|‘]?)([a-z])
Replace: \1 \3\u\4

Cheers!

Last edited by Turtle91; 12-31-2012 at 11:53 AM.
Turtle91 is offline   Reply With Quote