![]() |
#1 | |||
Junior Member
![]() 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:
Code:
<h1>Chapter 21: The New Beginning</h1> <p>Chapter 21: The New Beginning</p> Code:
<h1.*?>Chapter .*?</h1> <p>Chapter.*?</p> My issue is this, by pasting Code:
<h1.*?>.*?</h1> Quote:
Quote:
|
|||
![]() |
![]() |
![]() |
#2 |
Bibliophagist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 44,451
Karma: 167726581
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
|
Try wrapping the .*? in brackets. i.e. (.*?) which can be referenced by number. In the preplacement box, the first instance of (.*?) would be represented by \1, the second by \2, etc.
In your case I would use <h1 class="(.*?)">(.*?)</h1> <p class=".*?">.*?</p> as the search string and <h1 class="\1">\2</h1> as the replacement string. If the classes are fixed, you could simply use <h1 class="whatever">(.*?)</h1> and \1 for the chapter title in the replacement string. A quick visit to Regex 101 and playing with their test environment is a good idea. Last edited by DNSB; 04-01-2024 at 03:14 PM. |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Junior Member
![]() Posts: 2
Karma: 10
Join Date: Apr 2024
Device: none
|
Thank you very much. It worked
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Regex search and replace | yamusing | Library Management | 12 | 05-07-2020 01:19 PM |
Regex in search problems (NOT Search&Replace; the search bar) | lairdb | Calibre | 3 | 03-15-2017 07:10 PM |
regex search/replace - how to? | Alt68er | Sigil | 1 | 03-11-2014 08:53 PM |
Regex search and replace | dwlamb | Sigil | 6 | 04-12-2013 02:34 PM |
regex search/replace | Sharlene | Sigil | 10 | 01-28-2012 04:14 AM |