![]() |
The following expression should do the trick:
Find:<span class="Cap">(.)</span><span class="SmallCap">(.*?)</span> Replace:\1\L\2\E |
Quote:
Example: <span class="Cap">F</span><span class="SmallCap">IRST WORD OF THE SENTENCE IS ALWAYS CAPITALISED,</span> <span class="Cap">O</span><span class="SmallCap">THER</span> <span class="Cap">W</span><span class="SmallCap">WORDS IN THE SENTENCE MAY OR MAY NOT BE CAPITALISED</span> Desired result : First word of the sentence is always capitalised, Other Words in the sentence may or may not be capitalised. Actual result: First word of the sentence is always capitalised,</span> <span class="cap">o</span><span class="smallcap">ther</span> <span class="cap">w</span><span class="smallcap">words in the sentence may or may not be capitalised So I have lost some capital letters I want to preserve, and also for some reason even if I insert the cursor before the next opening tag of a complete pair, no other matches are found, and the code is broken. I have not found any way to fix this other than doing it by hand, I really don't know if it's possible to do it with regex to be honest*. Edit: *I should say, except by doing it in several passes, first <span class="Cap">(.)</span><span class="SmallCap">(.*?)</span> <span class="Cap">(.)</span><span class="SmallCap">(.*?)</span> <span class="Cap">(.)</span><span class="SmallCap">(.*?)</span> replace \1\L\2\E \3\L\4\E \5\L\6\E Then <span class="Cap">(.)</span><span class="SmallCap">(.*?)</span> <span class="Cap">(.)</span><span class="SmallCap">(.*?)</span> \1\L\2\E \3\L\4\E Then just one pair. But I'm interested to know if there is a way to manage all the cases in just one pass, in case you don't know in advance how many sets of spans there might be. |
Quote:
Find:<span class="Cap">(.)</span><span class="SmallCap">(.*?)</span> Replace:\1\L\2\E I'm getting: First word of the sentence is always capitalised, Other Wwords in the sentence may or may not be capitalised (None of the Regex options are checked.) You'll need to uncheck the Minimal Match option. |
Quote:
Well thanks very much for that tip, in future I will experiment more with minimal match and see when it is helpful and when not. |
Quote:
From the PCRE documentation: Quote:
|
Quote:
My original question was about fixing chapter headings to make it possible to easily regenerate a TOC, as I recently had a file with chapter headings in this format. To get back to that, is it possible to keep the original text as is, but copy the modified text into a title attribute, bearing in mind there can be a variable number of sets of spans in the title? I know how to do it with only one set, as I said, but except if I do it in multiple passes (3 sets then 2 sets then 1 set) I don't think this pattern works. For instance, a heading (that may or may not have a class and may or may not have an ID), and the text is in fake small-caps. Some titles may have one or more capitalised words in the middle but not all of them. I want to add the title attribute in sentence case. Find: <h1 class="chapter" id="id01"><span class="Cap">F</span><span class="SmallCap">IRST WORD OF THE SENTENCE IS ALWAYS CAPITALISED</span></h1> But also: <h1 class="chapter" id="id01"><span class="Cap">F</span><span class="SmallCap">IRST WORD OF THE SENTENCE IS ALWAYS CAPITALISED,OTHER</span> <span class="Cap">W</span><span class="SmallCap">ORDS IN THE SENTENCE MAY OR MAY NOT BE CAPITALISED</span></h1> And also: <h1 class="chapter" id="id01"><span class="Cap">F</span><span class="SmallCap">IRST WORD OF THE SENTENCE IS ALWAYS CAPITALISED,</span> <span class="Cap">O</span><span class="SmallCap">THER</span> <span class="Cap">W</span><span class="SmallCap">ORDS IN THE SENTENCE MAY OR MAY NOT BE CAPITALISED</span></h1> etc. Replace: <h1 class="chapter" id="id01" title="First word of the sentence is always capitalised, Other Words in the sentence may or may not be capitalised"><span class="Cap">F</span><span class="SmallCap">IRST WORD OF THE SENTENCE IS ALWAYS CAPITALISED,</span> <span class="Cap">O</span><span class="SmallCap">THER</span> <span class="Cap">W</span><span class="SmallCap">ORDS IN THE SENTENCE MAY OR MAY NOT BE CAPITALISED</span></h1> (and other variations with zero or more capitalised words in the middle of the title) I usually use some variation of this: Search: <h1 class="chapter" id="(.*)"><span class="Cap">(.)</span><span class="SmallCap">(.*)</span></h1> Replace: <h1 class="chapter" id="\1" title="\2\L\3\E"><span class="Cap">\2</span><span class="SmallCap">\3</span></h1> It works if there is only one set of spans. If there is more than one set I have to multiply the search variables and the replace variables so there are the same number of sets of each, for iterations of the same search, or correct them by hand one by one as I go along. |
Hi! I have chapters without titles and would like to add, to each one of them, their file names in the body text... is this regexable? Thanks!
:help: L |
Quote:
We have to have some kind of example to help you. Can you copy/paste a section of code that we can look at? |
Sure, thanks for helping....
The recurrent code for each chapter/file is the following : <head> My idea would be to Find/Replace in regex mode: <h2>Chapter</h2> with <h2><filename></h2> .... do you know if there is a regex code for <filename>?[....] </head> <body> <h2>Chapter</h2> Thanks Quote:
|
Unfortunately, I don't think what you want is possible. Not with Sigil's built-in regex Search & Replace feature anyway. Search and Replace doesn't know what the filename is. In this instance, it's merely searching the content given to it. Which is the contents of the file. The regex engine is unaware that what it's searching for (and replacing) is even part of a file. It's immaterial.
You (or someone) may be able to construct a sigil plugin that could accomplish this, but unless it's something you foresee happening a lot, developing a plugin to handle it would likely be more involved than just manually updating the chapter headers. Sorry. |
OK... Thanks!
:thanks: Quote:
|
You should be able to do it with the calibre editor. You can create a regex-functions. One of the parameters the file name where the match is found. A really dumb function to do this is:
Code:
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):Code:
(<body>)Code:
<body><h2>OEBPS/Text/Section0001.xhtml</h2>And for the record, I have another function called "Number Chapter" which can be used to number chapters across the complete book in one go. I don't remember if it a supplied function, or one mentioned in the forum that I copied. |
3 Attachment(s)
Hi luciaisacat,
I have played with the idea from davidfor and came up with the following solution for the calibre editor: 1. open your file in the calibre editor. 2. call search/replace, change to Mode: "regex-function", insert your search string and then click "create/edit" 3. you will see a basis function. 4. insert a name for your new Function and replace the code with: Code:
import reKlecks |
Remove Kobo spans
I just want to contribute a bit, as I found a way to remove Kobo spans:
Search: Code:
<span class="koboSpan" id="kobo.[0-9]{1,2}([.][0-9]{1,2})?">([^<>]+)</span>Code:
\2 |
Quote:
|
| All times are GMT -4. The time now is 07:52 PM. |
Powered by: vBulletin
Copyright ©2000 - 3.8.5, Jelsoft Enterprises Ltd.
MobileRead.com is a privately owned, operated and funded community.