07-02-2020, 08:11 AM | #1 |
Member
Posts: 14
Karma: 10
Join Date: Jun 2020
Device: Kindle
|
Regex replace p-class in entire book
Hi, I'm new at this so bear with me.
Trying to replace this... Code:
<p class="p23">[keep everything inside here]</p> Code:
<h1 class=“p15”>[keep everything inside here]</h1> I've tried Diaps Plugin but it's a bit beyond me. Any help sincerely appreciated! Thanks. |
07-02-2020, 08:38 AM | #2 |
Resident Curmudgeon
Posts: 73,970
Karma: 128903378
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Search for...
Code:
<p class="p23">(.*)</p> Code:
<h1 class="p15">\1</h1> |
07-03-2020, 10:26 AM | #3 |
Member
Posts: 14
Karma: 10
Join Date: Jun 2020
Device: Kindle
|
Thanks JS, but the replace code you suggested replaces the entire chapter.
I need to replace one open and closed p tag (with a nested span and chapter title inside it) with an h1 tag. That is, from this: Code:
<p class="p23"><span id="chapter-5"></span>Coming Home</p> Code:
<h1 class="p15"><span id="chapter-5"></span>Coming Home</p> Thanks in advance for your help! |
07-03-2020, 12:09 PM | #4 | |
Guru
Posts: 927
Karma: 1177583
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite
|
Quote:
Search: Code:
<p class="p23">(.*?)</p> Code:
<h1 class="p15">\1</h1> |
|
07-03-2020, 02:04 PM | #5 | |
Wizard
Posts: 1,071
Karma: 412718
Join Date: Jan 2009
Location: Valley Forge, PA, USA
Device: Kindle Paperwhite
|
Quote:
It's configurable so you can add additional tags This does what you asked, but it you want to key off of the id="chapter.." it's a little more complicated Result is Code:
<h1 class="p15"><span id="chapter-5"></span>Coming Home</h1> |
|
07-04-2020, 11:21 AM | #6 |
Member
Posts: 14
Karma: 10
Join Date: Jun 2020
Device: Kindle
|
Thanks Thiago!! It did the trick! Much appreciated :-)
Last edited by AlwaysNew; 07-04-2020 at 11:24 AM. |
07-04-2020, 11:28 AM | #7 | |
Member
Posts: 14
Karma: 10
Join Date: Jun 2020
Device: Kindle
|
Quote:
|
|
07-05-2020, 04:10 PM | #8 | |
Wizard
Posts: 2,082
Karma: 8796704
Join Date: Jun 2010
Device: Kobo Clara HD,Hisence Sero 7 Pro RIP, Nook STR, jetbook lite
|
Quote:
Quick reference for regexp syntax bernie |
|
07-09-2020, 04:37 AM | #9 |
Member
Posts: 14
Karma: 10
Join Date: Jun 2020
Device: Kindle
|
OK, I've tried using the regex as recommended, but now it's messing things up.
When I search this: Code:
<p class="p32">(.*?)</p> Code:
<h1 class="p20">(\1)</h1> Code:
<p class="p32"><span id="chapter-5"></span>Coming Home</p> Code:
<h1 class="p20">(<span id="chapter-5"></span>Coming Home)</h1> Any help truly appreciated as regex is not easy for me. |
07-09-2020, 04:39 AM | #10 |
Addict
Posts: 234
Karma: 291844
Join Date: Oct 2019
Device: Kobo Nia
|
In the replace, you do not need the round brackets. That is why the changed version shows brackets. You asked it to add them.
|
07-09-2020, 04:43 AM | #11 |
Well trained by Cats
Posts: 29,800
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Replace NEVER gets the (search) Capture Paren
\1 is the value that will be inserted When you included the LITERALS ( and ), that is what was ADDED, because that is what you told it to do. |
07-09-2020, 09:01 AM | #12 |
Resident Curmudgeon
Posts: 73,970
Karma: 128903378
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Question, why are we still going over this when @phossler gave the ultimate answer that works?
|
07-09-2020, 04:17 PM | #13 | |
Guru
Posts: 691
Karma: 3026110
Join Date: Dec 2008
Location: Lancashire, U.K.
Device: BeBook 1, BeBook Pure, Kobo Glo, (and HD),Energy Sistem EReader Pro +
|
Quote:
Does this involve some arcane tweaking of a file somewhere ? I have long tried to use the plug-in to achieve the task of converting a classed "p" tag to a "h" tag and have always had to do it by regex. As I see it the only thing you can change a "p" to is a "div". BobC |
|
07-09-2020, 04:40 PM | #14 |
Wizard
Posts: 1,071
Karma: 412718
Join Date: Jan 2009
Location: Valley Forge, PA, USA
Device: Kindle Paperwhite
|
I normally just use the parameters screen to add additional tags, but IIRC I did have to one time tweak (VERY carefully) the file:
Code:
C:\Users\......\AppData\Roaming\calibre\plugins\diaps_editing_toolba g_SpanDivEdit_settings.json Been awhile since, once I had everything set, there hasn't been any reason to change Last edited by phossler; 07-09-2020 at 04:50 PM. |
07-10-2020, 03:11 AM | #15 |
Member
Posts: 14
Karma: 10
Join Date: Jun 2020
Device: Kindle
|
|
Tags |
regex |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Regex for replacing class | AlwaysNew | Editor | 5 | 06-22-2020 08:55 AM |
Search and replace returns entire field when no match is found | wladdy | Calibre | 2 | 02-16-2014 01:51 AM |
Help with regex POSIX class search | bfollowell | Sigil | 7 | 05-21-2011 10:55 AM |
regex replace??? | schuster | Conversion | 14 | 01-29-2011 09:02 AM |
need regex help search and replace | schuster | Calibre | 4 | 01-10-2011 09:00 AM |