12-31-2012, 11:36 AM | #1 |
A Hairy Wizard
Posts: 3,068
Karma: 18727053
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
|
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. |
01-18-2013, 04:50 PM | #2 |
Connoisseur
Posts: 57
Karma: 10
Join Date: Dec 2011
Device: Samsung Tablet
|
Any news on something like this working?
|
01-18-2013, 08:23 PM | #3 |
Well trained by Cats
Posts: 29,688
Karma: 54369090
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Most Mixed case switches I have used require that you start with lower case.
so you could do this in 2 passes ( put a unique marker pair as part of the first replace) AND THE WORLD WAS FLAT +and the world was flat+ Now search for the pair \+(.+?)\+ and perform your magic |
01-19-2013, 01:36 PM | #4 | |
Connoisseur
Posts: 57
Karma: 10
Join Date: Dec 2011
Device: Samsung Tablet
|
Quote:
|
|
Thread Tools | Search this Thread |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Title Case and Handling Name Suffixes | rcandi | Calibre | 2 | 10-09-2011 10:30 AM |
upper case to sentence case conversion | cybmole | Sigil | 8 | 01-20-2011 06:03 AM |
Conversion to title case | Seanette | Calibre | 23 | 10-27-2010 01:01 PM |
Any chance of 'Title Case' being improved? | kiwidude | Calibre | 6 | 10-11-2010 12:40 PM |
Title Case | Dopedangel | Calibre | 6 | 10-16-2009 08:01 AM |