![]() |
#1 |
Member
![]() Posts: 14
Karma: 10
Join Date: Jun 2020
Device: Kindle
|
![]()
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. |
![]() |
![]() |
![]() |
#2 |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,665
Karma: 145864619
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> |
![]() |
![]() |
Advert | |
|
![]() |
#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! |
![]() |
![]() |
![]() |
#4 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,208
Karma: 1419583
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite, Kindle Oasis
|
Quote:
Search: Code:
<p class="p23">(.*?)</p> Code:
<h1 class="p15">\1</h1> |
|
![]() |
![]() |
![]() |
#5 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,087
Karma: 447222
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> |
|
![]() |
![]() |
Advert | |
|
![]() |
#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. |
![]() |
![]() |
![]() |
#7 | |
Member
![]() Posts: 14
Karma: 10
Join Date: Jun 2020
Device: Kindle
|
Quote:
|
|
![]() |
![]() |
![]() |
#8 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 2,181
Karma: 8888888
Join Date: Jun 2010
Device: Kobo Clara HD,Hisence Sero 7 Pro RIP, Nook STR, jetbook lite
|
Quote:
Quick reference for regexp syntax bernie |
|
![]() |
![]() |
![]() |
#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. |
![]() |
![]() |
![]() |
#10 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 243
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.
|
![]() |
![]() |
![]() |
#11 |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 31,016
Karma: 60358908
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. |
![]() |
![]() |
![]() |
#12 |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,665
Karma: 145864619
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?
|
![]() |
![]() |
![]() |
#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 |
|
![]() |
![]() |
![]() |
#14 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,087
Karma: 447222
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. |
![]() |
![]() |
![]() |
#15 |
Member
![]() Posts: 14
Karma: 10
Join Date: Jun 2020
Device: Kindle
|
|
![]() |
![]() |
![]() |
Tags |
regex |
|
![]() |
||||
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 |