12-26-2014, 07:33 PM | #1 |
Wizard
Posts: 1,085
Karma: 412718
Join Date: Jan 2009
Location: Valley Forge, PA, USA
Device: Kindle Paperwhite
|
RegEx Function: Title Case
Trying to use the wonderful new F&R functions to replace ALL CAPS headings
The fragment in the manual works unless there's a <br/> in the Hx tags So if it looks like <h1> CHAPTER 2 <br/>AWAY WE GO</h1> it seems that the embedded <br/> causes it to not find I cannot figure out how to modify the Find expression to handle that case What is the modifications needed? Thanks Last edited by phossler; 12-26-2014 at 09:28 PM. |
12-26-2014, 10:06 PM | #2 |
creator of calibre
Posts: 44,421
Karma: 24044628
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
(?s)<h\d>(.+?)</h\d>
|
Advert | |
|
12-27-2014, 11:06 AM | #3 |
Wizard
Posts: 1,085
Karma: 412718
Join Date: Jan 2009
Location: Valley Forge, PA, USA
Device: Kindle Paperwhite
|
Thanks, but it doesn't seem to find the test text
Is there a setting or something I should change? |
12-27-2014, 01:01 PM | #4 | |
Interested in the matter
Posts: 421
Karma: 426094
Join Date: Dec 2011
Location: Spain, south coast
Device: Pocketbook InkPad 3
|
Quote:
And naturally finds nothing. |
|
12-27-2014, 01:38 PM | #5 |
Wizard
Posts: 1,085
Karma: 412718
Join Date: Jan 2009
Location: Valley Forge, PA, USA
Device: Kindle Paperwhite
|
Yep, it was a trailing space
However, the < and > in the <br/> gets replaced by named enetities The end result seems to be they're treated like normal text instead of a tag So I'm wondering if it's even possible to title case multiple lines BTW, I do it that way so that the TOC has both lines as an entry: Chapter 1 Now It All Starts Chapter 2 And It Keeps On Going |
Advert | |
|
12-27-2014, 10:23 PM | #6 |
creator of calibre
Posts: 44,421
Karma: 24044628
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
(?s)<h\d>(.+?)<br>(.+?)</h\d>
|
12-28-2014, 11:35 AM | #7 | |
Wizard
Posts: 1,085
Karma: 412718
Join Date: Jan 2009
Location: Valley Forge, PA, USA
Device: Kindle Paperwhite
|
Thanks, but that RE doesn't seem to find anything. I made sure that there was no invisible trailing space in the Find expression ... this time
Quote:
Thanks |
|
12-28-2014, 12:22 PM | #8 |
Well trained by Cats
Posts: 30,416
Karma: 58055868
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
the BR did not include a space and self closing slash
Code:
(?s)<h\d>(.+?)<br\s*/>(.+?)</h\d>
the \s* handles the unpretty (no space) condition of your original |
12-28-2014, 12:44 PM | #9 |
creator of calibre
Posts: 44,421
Karma: 24044628
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
(?s)<h\d>(.+?)<br\s*/?>(.+?)</h\d>
|
12-28-2014, 01:55 PM | #10 |
Wizard
Posts: 1,085
Karma: 412718
Join Date: Jan 2009
Location: Valley Forge, PA, USA
Device: Kindle Paperwhite
|
Thanks to both of you for your help, but the Find string is still either finding too much or nothing, as well as returning entities which end up being ignored (i.e. the <br/> 's)
The User Manual example Code:
<[Hh][1-6][^>]*>([^<>]+)</[hH][1-6]> I'd appreciate any more ideas |
12-28-2014, 10:55 PM | #11 |
creator of calibre
Posts: 44,421
Karma: 24044628
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
I tried the following expression and it works both for heading tags with <br> inside and without br inside.
Code:
<[Hh][1-6][^>]*>([^<>]*)(?:<[^<>]+>){0,1}([^<>]*)</[hH][1-6]> |
12-29-2014, 09:16 AM | #12 |
Wizard
Posts: 1,085
Karma: 412718
Join Date: Jan 2009
Location: Valley Forge, PA, USA
Device: Kindle Paperwhite
|
Thanks very much
It will take me a while to understand it, but hopefully I'll learn some new reg ex techniques |
12-29-2014, 01:34 PM | #13 | |
null operator (he/him)
Posts: 20,960
Karma: 27620690
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
Quote:
I've no idea if its any good, but I find it useful to try to unravel obscure RE. BR Last edited by BetterRed; 12-29-2014 at 01:37 PM. |
|
12-29-2014, 02:54 PM | #14 |
Wizard
Posts: 1,085
Karma: 412718
Join Date: Jan 2009
Location: Valley Forge, PA, USA
Device: Kindle Paperwhite
|
@BR -- thanks. Very helpful.
I'm still looking for the RE that says "Do what I want" and not "What I Told You To Do" |
12-30-2014, 05:07 PM | #15 |
Wizard
Posts: 1,085
Karma: 412718
Join Date: Jan 2009
Location: Valley Forge, PA, USA
Device: Kindle Paperwhite
|
I'm wondering if I have an issue with the actual TitleCasing RegEx-Function?
For this fragment ... Code:
<body> <h1>TEST1 TEST1 TEST1 TEST1 TEST1 </h1> <p>NOW IS THE TIME and this should remain mixed case</p> <h1>TEST2 TEST2 TEST2 <br/><br/>TEST3 TEST3 </h1> <p>NOW IS THE TIME and this should remain mixed case</p> <h1>TEST4 <i>TEST4 TEST4 TEST4</i> TEST4 </h1> </body> ... my Find expression Code:
\<([Hh][1-6])\>.*?\</\1\> It would seem to me that if the built in Title Case would ignore tags and what's in them, and just act on the 'Find' it should / would work for any embedded tags inside Hx pairs not just <br/> Am I misunderstanding? Last edited by phossler; 12-30-2014 at 05:10 PM. Reason: Can't type |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
regex-function convert roman numerals | weberr | Editor | 11 | 09-22-2021 05:15 PM |
A regex function to number a mathematical ebook | dmonasse | Editor | 3 | 12-23-2014 02:54 AM |
Regex Function - Split unknown word | Paulie_D | Editor | 19 | 12-07-2014 05:12 AM |
Regex for Title Case or Sentence case? | Turtle91 | Sigil | 3 | 01-19-2013 01:36 PM |
Dutch title case function | fvdham | Library Management | 8 | 10-11-2012 10:09 PM |