![]() |
A regex question
I have hundreds of subtitles throughout a cookbook, and would like to know if there is a way to do a search and replace to give all these titles an h3 designation:
Quote:
I only have a rudimentary understanding of regex and just tried a few things, but nothing would work. Any ideas? |
If all the subtitles are <p class="calibre8" id="filepos######"><span class="calibre6 bold">
With other paragraphs not using those. If they are you should be good to use this for search (regex mode) Code:
<p class="calibre8" id="filepos\d+"><span class="calibre6 bold">(.+?)</span></p>Code:
<h3>\1</h3> |
Quote:
Code:
<p class="calibre8" id="filepos170176"><span class="calibre6 bold"><span class="italic">Spicy Escarole with Croutons and Eggs</span></span></p> |
Shoud be fairly safe though as I was doing opening p+span, with matching closing span+p
Would result in italic span being inserted in the header tag, while not necessarily wanted, also wouldn't be illegal etc.. |
Perkin, thanks a million for your help. Your solution worked perfectly.
Kudos to all you regex experts. I've tried to wrap my head around this but I can never quite grasp it. Or I grasp the basic principles, then after a few months I've completely forgotten it as I use regex so infrequently! |
While there are some regex experts here, two more questions:
1) Is it possible to change all-caps text in a toc.ncx file to initial caps? For example I would like to change: <text>ICE CREAM</text> to <text>Ice Cream</text> 2) Is it possible to have some of the items in the metadata TOC underlined or italicized? I get the feeling this is not possible but I am not sure. |
Quote:
<h3>ICE CREAM</h3> you could use: <h3 title="Ice Cream">ICE CREAM</h3> |
Quote:
|
Quote:
I don't know about the Regex, but if you look close at my example you will see that title= overrides what is between the H3 tags, but leaves what is on the Page alone. <h3 title="Ice Cream with topping">ICE CREAM</h3> in this version Sigil would create a TOC entry: Ice Cream with topping But the page would show plain Vanilla :p |
@ PatNY
Take a look at this page for Ideas: http://vim.wikia.com/wiki/Changing_c...ar_expressions |
This works in the Body for 2 words
Code:
<h3>(([A-Z])(.+) ([A-Z])(.+))</h3>:thumbsup: |
Quote:
IOW, how do I turn "<text>ICE CREAM</text>" into "<text>Ice Cream</text>" :blink: |
OK, ducks, I tried to adapt your formula to the specific issue I had by using this:
Find: <text>(([A-Z])(.+) ([A-Z])(.+))</text> Replace: <text>\2\L\3\E \4\L\5\E</text> And it's mostly working. However If I have more than two words in the title, then only the first and last words get the initial cap. The words in the middle are all lower case. So, for example, your solution will result in: <text>Ice cream Rocks</text> instead of <text>Ice Cream Rocks</text> So, do you know how to get every word in the title to be initial caps? |
He's telling you to change the code in the book body, in the HTML, not in the toc.ncx. Sigil will generate the toc.ncx entries for you, using the "title" attribute instead of the content between the header tags.
|
Quote:
First off, I only need to change the case of words in the TOC.ncx, so I don't see the need to alter other files. I want to make as few changes as possible in the html files. That way if anything goes wrong, it's easier to identify the problem and correct it if it's limited to just the one toc.ncx file rather than having to examine and sift through potentially hundreds of pages in html files. Second, going forward, there could be literally dozens of permutations in the variety of the tags surrounding a title in the html files. That would mean the exact formula might have to change every time, depending on what the set of tags was. I would have a hard time adjusting that formula every time. However, the "<text>WORDS GO HERE</text>" tag construction in the TOC.ncx file is the same all the time. So one formula should solve the problem, every time no matter what. Ducks got me halfway there. I can change all-caps titles into initial-caps words in the TOC, but it doesn't work for all the words in a title -- just the first and last! |
| All times are GMT -4. The time now is 07:53 PM. |
Powered by: vBulletin
Copyright ©2000 - 3.8.5, Jelsoft Enterprises Ltd.
MobileRead.com is a privately owned, operated and funded community.