09-30-2020, 12:55 PM | #1 |
A Hairy Wizard
Posts: 3,095
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
|
Keyboard Shortcut in Regex?
I'm still trying to figure out a way to convert text to Title Case without having to manually select the text each time....short of writing a plugin to include formulaic regex like Calibre uses.
I have TitleCase assigned as a keyboard shortcut (Ctrl+Space) and wondered if there was a way to use that shortcut in the 'replace' section of the regex...resulting in something like: find: (?<=\<h2\>)(.*?)(?=\</h2\>) replace: Ctrl+Space |
09-30-2020, 02:17 PM | #2 |
Running with scissors
Posts: 1,552
Karma: 14325282
Join Date: Nov 2019
Device: none
|
What's so special about the keyboard shortcut? I use the following saved search:
find: <h([\d]+)>(.)(.*)</h[\d]+> replace: <h\1>\2\L\3</h\1> |
09-30-2020, 02:21 PM | #3 |
Running with scissors
Posts: 1,552
Karma: 14325282
Join Date: Nov 2019
Device: none
|
I'm certainly no regexp wizard; what's the ?<= at the beginning of the h2 match doing? And why do you have backslashes in front of the < and >?
|
09-30-2020, 02:23 PM | #4 |
Running with scissors
Posts: 1,552
Karma: 14325282
Join Date: Nov 2019
Device: none
|
I'm so used to typing [\d]+ and I just noticed that I used it here; probably could remove the square brackets as well as the plus sign.
find: <h(\d)>(.)(.*)</h\d> But at least I'm ready for when the HTML standard adds an h10 tag. Last edited by hobnail; 09-30-2020 at 02:25 PM. |
09-30-2020, 02:29 PM | #5 | |
Grand Sorcerer
Posts: 27,552
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
Quote:
He's just escaping the the angle brackets with the backslash--though there's no real reason to since they aren't regex metacharacters to begin with. How does your regex deal with more than one word between the h tags? Last edited by DiapDealer; 09-30-2020 at 02:42 PM. |
|
09-30-2020, 02:45 PM | #6 | |
Running with scissors
Posts: 1,552
Karma: 14325282
Join Date: Nov 2019
Device: none
|
Quote:
Even though I was born and raised in the US I was taught that sentence case is better. E.g., see https://atmosol.com/resource-post/he...sentence-case/. Ease of regex construction for it is now another argument in its favor. Last edited by hobnail; 09-30-2020 at 03:04 PM. |
|
09-30-2020, 03:22 PM | #7 | |
A Hairy Wizard
Posts: 3,095
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
|
Quote:
Yes, I am trying to get Title Case rather than Sentence case. This would be the first step, followed by a pass to change ' Of ', ' And ', ' The ', etc. to 'of, and, the. I'm sure there are plenty of other exceptions that I haven't come across yet... |
|
09-30-2020, 03:50 PM | #8 |
Running with scissors
Posts: 1,552
Karma: 14325282
Join Date: Nov 2019
Device: none
|
|
09-30-2020, 07:42 PM | #9 |
Grand Sorcerer
Posts: 27,552
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
And to officially answer the original question: no. I'm afraid you can't fire off a keyboard shortcut with regex. I'd love to be able to say differently, but I can't.
And even a straight-up capitalize the first letter of every word (making sure everything else is lower-case) between two tags is going to very difficult to pull off with S&R regex alone. |
09-30-2020, 09:16 PM | #10 | |||
Wizard
Posts: 2,297
Karma: 12126329
Join Date: Jul 2012
Device: Kobo Forma, Nook
|
Quote:
1. Use Calibre's Functions. An example is even given in the manual: "Automatically fixing the case of headings in the document" 2. AutoHotKey. If I want to "speed up" annoying shortcuts, I sometimes assign one of the extra buttons on my mouse. For example, this AutoHotKey line: Code:
XButton2::^q Then a (previously annoying) click+shortcut combo becomes a simple: 1. Left-Click 2. Side-Click 3. Left-Click 4. [...] If you want to get fancy, you could even have AutoHotKey click the "Find" button for you too! Then all you have to do is keep pressing the side button! Quote:
"Add title="" to h* based on existing TOC -- suggestion for new feature (or plugin?)" Especially see my Posts #11, #13, and #15. (I even spent a day writing up the ultimate "Title Casing: Everything You Didn't Know You Ever Wanted to Know" post... yet to be released though.*) Quote:
But even with "easy" Sentence Case, you have to take into account things like:
... It's all mentioned in my ultimate guide.* - - - - - (* If anyone's interested, I could send you the rough draft via PM... or you could wait until my blog gets rolling! ) Last edited by Tex2002ans; 10-01-2020 at 12:52 AM. |
|||
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
keyboard shortcut request | rjwse@aol.com | Calibre | 3 | 10-17-2019 04:31 PM |
keyboard shortcut request | rjwse@aol.com | Calibre | 0 | 10-16-2019 12:05 PM |
Keyboard Shortcut | Fbone | Calibre | 4 | 11-03-2015 08:15 PM |
Keyboard Shortcut for <li>? | Rand Brittain | Editor | 7 | 02-25-2015 09:15 AM |
Keyboard Shortcut: Rename | CRB_Clive | General Discussions | 1 | 04-01-2014 01:32 PM |