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 06-18-2020, 07:54 AM   #1
AlwaysNew
Member
AlwaysNew began at the beginning.
 
Posts: 14
Karma: 10
Join Date: Jun 2020
Device: Kindle
Regex for replacing class

Hi, can anyone help in replacing this class with nested code inside, throughout multiple documents?

From
Code:
<p class="p23"><span id=“ [chapter number] ”></span> [chapter title] </p>
To
Code:
<h1 class="p23"><span id=“ [chapter number] ”></span> [chapter title] </h1>
Thanks!
AlwaysNew is offline   Reply With Quote
Old 06-18-2020, 10:31 AM   #2
gbm
Wizard
gbm ought to be getting tired of karma fortunes by now.gbm ought to be getting tired of karma fortunes by now.gbm ought to be getting tired of karma fortunes by now.gbm ought to be getting tired of karma fortunes by now.gbm ought to be getting tired of karma fortunes by now.gbm ought to be getting tired of karma fortunes by now.gbm ought to be getting tired of karma fortunes by now.gbm ought to be getting tired of karma fortunes by now.gbm ought to be getting tired of karma fortunes by now.gbm ought to be getting tired of karma fortunes by now.gbm ought to be getting tired of karma fortunes by now.
 
Posts: 2,178
Karma: 8800000
Join Date: Jun 2010
Device: Kobo Clara HD,Hisence Sero 7 Pro RIP, Nook STR, jetbook lite
Quote:
Originally Posted by AlwaysNew View Post
Hi, can anyone help in replacing this class with nested code inside, throughout multiple documents?

From
Code:
<p class="p23"><span id=“ [chapter number] ”></span> [chapter title] </p>
To
Code:
<h1 class="p23"><span id=“ [chapter number] ”></span> [chapter title] </h1>
Thanks!
Quick and dirty but works.
Question does your span id have spaces around the number?
Search:

Code:
<p class="p(\d+)"><span id=“(\d+)”></span>(.*?)</p>
Replace:
Code:
<h1 class="p23"><span id=“\1”></span>\2</h1>
bernie
Attached Thumbnails
Click image for larger version

Name:	Screenshot from 2020-06-18 10-20-50.png
Views:	198
Size:	155.0 KB
ID:	179976   Click image for larger version

Name:	Screenshot from 2020-06-18 10-30-42.png
Views:	186
Size:	158.0 KB
ID:	179978  
gbm is offline   Reply With Quote
Advert
Old 06-18-2020, 02:41 PM   #3
hobnail
Running with scissors
hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.
 
Posts: 1,584
Karma: 14328510
Join Date: Nov 2019
Device: none
This plugin is designed exactly for that task; no need for regular expressions. Although it does allow you to use them if you want to match multiple classes and such.

https://www.mobileread.com/forums/sh....php?p=2980740
hobnail is offline   Reply With Quote
Old 06-19-2020, 03:42 AM   #4
AlwaysNew
Member
AlwaysNew began at the beginning.
 
Posts: 14
Karma: 10
Join Date: Jun 2020
Device: Kindle
Quote:
Originally Posted by gbm View Post
Quick and dirty but works.
Question does your span id have spaces around the number?
Search:

Code:
<p class="p(\d+)"><span id=“(\d+)”></span>(.*?)</p>
Replace:
Code:
<h1 class="p23"><span id=“\1”></span>\2</h1>
bernie
Thanks, but I think I was not clear enough. I already have the chapter numbers and titles in each file, I just want to change the beginning class and its closing tag from <p to <h1 and leave the nested code as is.

Make sense?
AlwaysNew is offline   Reply With Quote
Old 06-22-2020, 08:00 AM   #5
thiago.eec
Wizard
thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.
 
Posts: 1,198
Karma: 1355861
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite, Kindle Oasis
Quote:
Originally Posted by AlwaysNew View Post
Thanks, but I think I was not clear enough. I already have the chapter numbers and titles in each file, I just want to change the beginning class and its closing tag from <p to <h1 and leave the nested code as is.

Make sense?
If the "p23" class is fix, then you could just use this:

Search:
Code:
<p class="p23">(.*?)</p>
Replace:
Code:
<h1 class="p23">\1</h1>
thiago.eec is offline   Reply With Quote
Advert
Old 06-22-2020, 08:55 AM   #6
Terisa de morgan
Grand Sorcerer
Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.
 
Terisa de morgan's Avatar
 
Posts: 6,608
Karma: 12595249
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
You can check this plugin (Diap's Editing toolbag), which does exactly that and other replacements in an easier way.
Terisa de morgan is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Aura H2O MicroSDHC card class 4 or class 10? chipro12 Kobo Reader 5 07-04-2015 02:24 AM
Replacing with regex 1v4n0 Sigil 11 01-17-2015 02:07 PM
PRS-650 SD Card Importance? SDHC, SDHC Class 4, Class 10 etc is it important Renji Sony Reader 11 12-03-2011 12:30 PM
Replacing code without replacing text? ElMiko Sigil 6 11-30-2011 08:14 PM
Help with regex POSIX class search bfollowell Sigil 7 05-21-2011 10:55 AM


All times are GMT -4. The time now is 04:36 PM.


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