View Single Post
Old 04-01-2024, 07:47 AM   #1
darrnih
Junior Member
darrnih began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Apr 2024
Device: none
how to replace text with Search and Replace with regex on Calibre

So, I have a book I'm listening to using text-to-speech, but at the start of each chapter, the heading is written twice. With the tags "<h1>" and "<p>".
This ends up showing the title of the chapter in both heading and normal fonts, which isn't an issue when reading, but when listening, the text-to-speech will have to repeat it twice which is a bit annoying.
To solve this, I downloaded calibre and discovered Regex, so I went about a beginner tutorial and realised that I could isolate each instance this happened.
If I have something like
Quote:
Chapter 21: The New Beginning
Chapter 21: The New Beginning
Which would appear like this in the editor.
Code:
<h1>Chapter 21: The New Beginning</h1>
<p>Chapter 21: The New Beginning</p>
By running the code below in the search tab to search through the entire file
Code:
<h1.*?>Chapter .*?</h1>
    <p>Chapter.*?</p>
I'm able to capture any instance of the title appearing twice.
My issue is this, by pasting
Code:
<h1.*?>.*?</h1>
in the replace tab, instead of it replacing the text with what was supposed to be inside the "<h1>" tag, so in this case I expect to see
Quote:
Chapter 21: The New Beginning
Instead I get,
Quote:
<h1.*?>.*?</h1>
Is there a way to save the string gotten from the first code into the second
darrnih is offline   Reply With Quote