Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 05-06-2023, 05:59 AM   #1
Dr.Strangelove
Member
Dr.Strangelove began at the beginning.
 
Posts: 15
Karma: 10
Join Date: Mar 2019
Location: Hamburg/Germany
Device: Kindle Paperwhite 7. Generation
need help to create a regex

I have an epub which has tags like this in html
Code:
 <body id="CCNA0-13649bfe67614ed3be03405aa6e1ffaf" class="calibre">
and this in toc.ncx
Code:
<content src="text/part0011.html#AFM60-13649bfe67614ed3be03405aa6e1ffaf"/>
For the first line, I need to replace it with
Code:
<body class="calibre">
whatever the id is.

For the second my idea is to replace
Code:
html#AFM60-13649bfe67614ed3be03405aa6e1ffaf"
against
Code:
html"
- again whatever the long id is.Could somebody help me with the regex? I am not able to find a way using wildcards for the id
Dr.Strangelove is offline   Reply With Quote
Old 05-06-2023, 06:47 AM   #2
Karellen
Wizard
Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.
 
Karellen's Avatar
 
Posts: 1,592
Karma: 9499994
Join Date: Sep 2021
Location: Australia
Device: Kobo Libra 2
Try...

find: <body id=".*?" class="calibre">
replace: <body class="calibre">

find: html#.*?"
replace: html"
Karellen is offline   Reply With Quote
Advert
Old 05-06-2023, 06:56 AM   #3
Tex2002ans
Wizard
Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.
 
Posts: 2,306
Karma: 13057279
Join Date: Jul 2012
Device: Kobo Forma, Nook
I'd tweak it slightly with a much more narrow:

Find: <body id="[^"]+" class="calibre">
Replace: <body class="calibre">

Find: html#[^"]+"/>
Replace: html"/>

Those 2 regexes are kind of saying:
  • "Hey! Keep going as long as you're NOT a quotation mark!"

It's a little bit safer than .*?, which can sometimes go crazy if you weren't expecting it.

Last edited by Tex2002ans; 05-06-2023 at 07:00 AM.
Tex2002ans is offline   Reply With Quote
Old 05-06-2023, 06:58 AM   #4
Dr.Strangelove
Member
Dr.Strangelove began at the beginning.
 
Posts: 15
Karma: 10
Join Date: Mar 2019
Location: Hamburg/Germany
Device: Kindle Paperwhite 7. Generation
@Karellen
The first one works like a charm. I needed to change the second one to
Code:
html#.*"
otherwise it includes too much.

Thank you!

Last edited by Dr.Strangelove; 05-06-2023 at 07:00 AM.
Dr.Strangelove is offline   Reply With Quote
Old 05-06-2023, 07:00 AM   #5
Dr.Strangelove
Member
Dr.Strangelove began at the beginning.
 
Posts: 15
Karma: 10
Join Date: Mar 2019
Location: Hamburg/Germany
Device: Kindle Paperwhite 7. Generation
Quote:
Originally Posted by Tex2002ans View Post
I'd tweak it slightly with a much more narrow:

Find: <body id="[^"]+" class="calibre">
Replace: <body class="calibre">

Find: html#[^"]+"/>
Replace: html"/>

Those 2 regex are kind of saying:
  • "Hey! Keep going as long as you're NOT a quotation mark!"

It's a little bit safer than .*?, which can sometimes go crazy if you weren't expecting it.
works also, thanks!
Dr.Strangelove is offline   Reply With Quote
Advert
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
pdf regex question - regex that wraps to a new line flyash Conversion 1 09-05-2021 09:00 AM
Predefined regex for Regex-function sherman Editor 3 01-19-2020 05:32 AM
Need help with RegEx Gary Friedman Editor 8 01-26-2017 08:37 AM
Help with some regex Chaos_Therum Library Management 1 12-28-2013 11:20 AM
New help with a regex txckie Calibre 2 08-29-2011 08:46 PM


All times are GMT -4. The time now is 12:20 PM.


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