10-07-2024, 07:14 AM | #1 |
Zealot
Posts: 118
Karma: 16268
Join Date: Apr 2020
Device: none
|
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 |
10-07-2024, 08:12 AM | #2 |
Guru
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> Code:
<h4>\1</h4> 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. |
Advert | |
|
10-08-2024, 01:51 AM | #3 |
Zealot
Posts: 118
Karma: 16268
Join Date: Apr 2020
Device: none
|
Boom! Perfect! Worked like a CHARM! Can't thank you enough. ))!!!!!!!!!!!!
|
10-09-2024, 04:53 PM | #4 |
Morlock
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.
|
|
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 |