Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Editor

Notices

Reply
 
Thread Tools Search this Thread
Old 10-07-2024, 07:14 AM   #1
Blaineoreski
Zealot
Blaineoreski exercises by bench pressing the entire Harry Potter series in hardcoverBlaineoreski exercises by bench pressing the entire Harry Potter series in hardcoverBlaineoreski exercises by bench pressing the entire Harry Potter series in hardcoverBlaineoreski exercises by bench pressing the entire Harry Potter series in hardcoverBlaineoreski exercises by bench pressing the entire Harry Potter series in hardcoverBlaineoreski exercises by bench pressing the entire Harry Potter series in hardcoverBlaineoreski exercises by bench pressing the entire Harry Potter series in hardcoverBlaineoreski exercises by bench pressing the entire Harry Potter series in hardcoverBlaineoreski exercises by bench pressing the entire Harry Potter series in hardcoverBlaineoreski exercises by bench pressing the entire Harry Potter series in hardcoverBlaineoreski exercises by bench pressing the entire Harry Potter series in hardcover
 
Blaineoreski's Avatar
 
Posts: 118
Karma: 16268
Join Date: Apr 2020
Device: none
Question Can't Search and replace Regex

Hi,

Using Calibre's Editor I can see the following code:

<p class="noindent"><span class="txbdit">SOME TEXT</span>

I want to change all instances to h4

<h4>SOME TEXT</h4>

I've used

Mode: Regex Wrap checked, Dot all, checked

It keeps saying, "0 Replacements"

I've tried the following syntaxes:

<p class="noindent"><span class="txbdit">(.*?)</span>

<h4>$1</h4>


<p class="noindent"><span class="txbdit">.*?</span>

<h4>$1</h4>


AS WELL AS
<p\s+class="noindent"><span\s+class="txbdit">.*? </span>

<p\s*class="noindent"\s*><span\s*class="txbdit"\s* >.*?</span>


INTERESTINGLY
I cannot search or replace even

<p>
<h4>

But, searching and replacing for

<p class="noindent">
Pericles

Works.

What do you think is happening?

https://ibb.co/Lkj9KKN
Blaineoreski is offline   Reply With Quote
Old 10-07-2024, 08:12 AM   #2
enuddleyarbl
Guru
enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.
 
enuddleyarbl's Avatar
 
Posts: 751
Karma: 1537886
Join Date: Sep 2013
Device: Kobo Forma
To me, the error implies a problem with the Search phrase. But, the thing that hits me is in the replacement string. Instead of:
Code:
<h4>$1</h4>
use:
Code:
<h4>\1</h4>
Calibre's Editor (which uses the Python flavor or regex) uses \ instead of $ for replacement groups.

EDIT: In the Search phrase, I'd also try .+? instead of .*?. According to:

https://regex101.com/

.*? means:

"1st Capturing Group (.*?)
. matches any character (except for line terminators)
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)"

and

.+? means

"1st Capturing Group (.+?)
. matches any character (except for line terminators)
+? matches the previous token between one and unlimited times, as few times as possible, expanding as needed (lazy)"

The difference being the lower number of matches (0 vs 1).

Last edited by enuddleyarbl; 10-07-2024 at 09:16 AM.
enuddleyarbl is offline   Reply With Quote
Advert
Old 10-08-2024, 01:51 AM   #3
Blaineoreski
Zealot
Blaineoreski exercises by bench pressing the entire Harry Potter series in hardcoverBlaineoreski exercises by bench pressing the entire Harry Potter series in hardcoverBlaineoreski exercises by bench pressing the entire Harry Potter series in hardcoverBlaineoreski exercises by bench pressing the entire Harry Potter series in hardcoverBlaineoreski exercises by bench pressing the entire Harry Potter series in hardcoverBlaineoreski exercises by bench pressing the entire Harry Potter series in hardcoverBlaineoreski exercises by bench pressing the entire Harry Potter series in hardcoverBlaineoreski exercises by bench pressing the entire Harry Potter series in hardcoverBlaineoreski exercises by bench pressing the entire Harry Potter series in hardcoverBlaineoreski exercises by bench pressing the entire Harry Potter series in hardcoverBlaineoreski exercises by bench pressing the entire Harry Potter series in hardcover
 
Blaineoreski's Avatar
 
Posts: 118
Karma: 16268
Join Date: Apr 2020
Device: none
Boom! Perfect! Worked like a CHARM! Can't thank you enough. ))!!!!!!!!!!!!

Blaineoreski is offline   Reply With Quote
Old 10-09-2024, 04:53 PM   #4
DyckBook
Morlock
DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.
 
DyckBook's Avatar
 
Posts: 34
Karma: 2734796
Join Date: Oct 2021
Device: Kindle Paperwhite
Can't Search and replace Regex

In order to avoid accidently capturing too much in the search I would replace (.*?) with ([^<]*) This will select only up to, but not including, the following </span> tag.
DyckBook is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to replace text with Search and Replace with regex on Calibre darrnih ePub 2 04-02-2024 03:10 AM
Regex search and replace yamusing Library Management 12 05-07-2020 02:19 PM
Regex in search problems (NOT Search&Replace; the search bar) lairdb Calibre 3 03-15-2017 08:10 PM
Regex search and replace dwlamb Sigil 6 04-12-2013 03:34 PM
regex search/replace Sharlene Sigil 10 01-28-2012 05:14 AM


All times are GMT -4. The time now is 12:48 AM.


MobileRead.com is a privately owned, operated and funded community.