Register Guidelines E-Books Search Today's Posts Mark Forums Read

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: 1,691
Karma: 5980951
Join Date: Jun 2010
Device: Windows 10 tablet,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:	29
Size:	155.0 KB
ID:	179976   Click image for larger version

Name:	Screenshot from 2020-06-18 10-30-42.png
Views:	26
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: 570
Karma: 2959442
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
Addict
thiago.eec can grok the meaning of the universe.thiago.eec can grok the meaning of the universe.thiago.eec can grok the meaning of the universe.thiago.eec can grok the meaning of the universe.thiago.eec can grok the meaning of the universe.thiago.eec can grok the meaning of the universe.thiago.eec can grok the meaning of the universe.thiago.eec can grok the meaning of the universe.thiago.eec can grok the meaning of the universe.thiago.eec can grok the meaning of the universe.thiago.eec can grok the meaning of the universe.
 
Posts: 377
Karma: 155004
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite
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: 5,448
Karma: 5761403
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

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 01:30 AM.


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