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 03-25-2026, 07:20 AM   #1
rjwse@aol.com
Addict
rjwse@aol.com ought to be getting tired of karma fortunes by now.rjwse@aol.com ought to be getting tired of karma fortunes by now.rjwse@aol.com ought to be getting tired of karma fortunes by now.rjwse@aol.com ought to be getting tired of karma fortunes by now.rjwse@aol.com ought to be getting tired of karma fortunes by now.rjwse@aol.com ought to be getting tired of karma fortunes by now.rjwse@aol.com ought to be getting tired of karma fortunes by now.rjwse@aol.com ought to be getting tired of karma fortunes by now.rjwse@aol.com ought to be getting tired of karma fortunes by now.rjwse@aol.com ought to be getting tired of karma fortunes by now.rjwse@aol.com ought to be getting tired of karma fortunes by now.
 
rjwse@aol.com's Avatar
 
Posts: 348
Karma: 2581190
Join Date: Dec 2013
Location: LaVernia, Texas
Device: kindle epub readers on android
regex class search

Sometimes the simplest things really give me a kick. I use classes almost exclusively instead of styles. My CSS is a long list of classes in the main consisting of the first letter of each word in every which kind of style definition. In this way I can quickly hop and chop from this to that. I got stumped on how to use calibre's 'find' for any kind of class name consisting of one or more letters. It got lost due to being surrounded by spaces, other classes, or quotation marks. So I asked AI and it gave me: class="[^"]*X[^"]*"
I remove X and put in whatever I am looking for, then make sure the search says 'regex' instead of 'fuzzy.' I also put it in 'saved searches' in case I forget.
Attached Thumbnails
Click image for larger version

Name:	Screenshot from 2026-03-25 06-07-36.png
Views:	48
Size:	613.5 KB
ID:	222044  
rjwse@aol.com is offline   Reply With Quote
Old 03-28-2026, 02:37 PM   #2
dunhill
Wizard
dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.
 
dunhill's Avatar
 
Posts: 1,091
Karma: 1084520
Join Date: Sep 2017
Location: Buenos Aires, Argentina
Device: moon+ reader, kindle paperwhite
Quote:
Originally Posted by rjwse@aol.com View Post
Sometimes the simplest things really give me a kick. I use classes almost exclusively instead of styles. My CSS is a long list of classes in the main consisting of the first letter of each word in every which kind of style definition. In this way I can quickly hop and chop from this to that. I got stumped on how to use calibre's 'find' for any kind of class name consisting of one or more letters. It got lost due to being surrounded by spaces, other classes, or quotation marks. So I asked AI and it gave me: class="[^"]*X[^"]*"
I remove X and put in whatever I am looking for, then make sure the search says 'regex' instead of 'fuzzy.' I also put it in 'saved searches' in case I forget.
You could try this:
Exact Search (Without False Positives)
If you want to find the exact class `bc` (for example, `background-color`) and avoid finding `abc` or `bcc`, use this variation:

`class="[^"]*(^|\s)bc(\s|$)[^"]*"`

`(^|\s)`: Ensures that your class name is preceded by a quote or a space.

`(\s|$)`: Ensures that it is followed by a space or a closing quote.

Searching for Classes Starting with...`
If, on the other hand, you want to see all the classes that define something related to the border (assuming they all start with `b`), you can use:

`class="[^"]*(^|\s)b[a-z]*(\s|$)[^"]*"`
dunhill is offline   Reply With Quote
Old 03-28-2026, 02:59 PM   #3
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,808
Karma: 9501034
Join Date: Sep 2021
Location: Australia
Device: Kobo Libra 2
Curious to know how many errors are reported when using epubCheck and checkbook.
Karellen is offline   Reply With Quote
Old 03-28-2026, 08:58 PM   #4
lomkiri
Groupie
lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.
 
lomkiri's Avatar
 
Posts: 190
Karma: 1537710
Join Date: Jul 2021
Device: N/A
Quote:
Originally Posted by dunhill View Post
You could try this:
`class="[^"]*(^|\s)bc(\s|$)[^"]*"`

`(^|\s)`: Ensures that your class name is preceded by a quote or a space.

`(\s|$)`: Ensures that it is followed by a space or a closing quote.
I don't agree with you:
(^|\s)bc : Ensures that bc is at the beginning of the line (which never happens since you put class="[^"]* before this expression) or after \s

bc(\s|$) : same problem, ensures that bc is at the EoL (never happens) or before \s

So it would select class="ab bc de" but neither class="ab bc" nor class="bc cd ef"

A working regexp would be :
class="[^"]*?\s*\Kbc(?=[\s"])
it will select only bc in the class (only the first one if there is several of it)
\K asks for resetting the chain (forget what is before \K)
(?=[\s"]) is a lookahead, it selects bc only if it's followed by \s or "

Quote:
Originally Posted by dunhill View Post
If, on the other hand, you want to see all the classes that define something related to the border (assuming they all start with `b`), you can use:

`class="[^"]*(^|\s)b[a-z]*(\s|$)[^"]*"`
There is also _ and - to be considered.
In that case, this one does the job (finds only the 1st one):
class="[^"]*?\s*\Kbc[\w-]*(?=[\s"])

or, if you want bc and up to 3 more char (e.g. bc, bcd, bcdef, bc-d, bc_de)
class="[^"]*?\s*\Kbc[\w-]{0,3}(?=[\s"])
(change {0,3} for whatever number you need)

Last edited by lomkiri; 03-28-2026 at 09:11 PM.
lomkiri is offline   Reply With Quote
Old 03-28-2026, 11:39 PM   #5
dunhill
Wizard
dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.
 
dunhill's Avatar
 
Posts: 1,091
Karma: 1084520
Join Date: Sep 2017
Location: Buenos Aires, Argentina
Device: moon+ reader, kindle paperwhite
You're right, Lomkiri. My approach with (^|\s) and (\s|$) aimed to emulate word boundaries, but indeed, start and end line anchors can cause problems depending on the HTML formatting. That's why I suggested trying it, but your use of \K is much more precise, especially since it allows you to select only the class without dragging the class=" attribute. Great contribution!
dunhill is offline   Reply With Quote
Old 03-29-2026, 05:44 AM   #6
lomkiri
Groupie
lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.
 
lomkiri's Avatar
 
Posts: 190
Karma: 1537710
Join Date: Jul 2021
Device: N/A
You're right, with word boundaries (\b), my 2nd and 3rd regex (for words starting with bc) are more elegant:
class="[^"]*?\K\bbc[\w-]*\b
class="[^"]*?\K\bbc[\w-]{0,3}\b

In the 1st one, we have to keep the lookahead to not have a match with "bc" in "bc-de"
class="[^"]*?\K\bbc(?=[\s"])

Last edited by lomkiri; 03-29-2026 at 05:55 AM.
lomkiri is offline   Reply With Quote
Old 03-29-2026, 07:48 AM   #7
rjwse@aol.com
Addict
rjwse@aol.com ought to be getting tired of karma fortunes by now.rjwse@aol.com ought to be getting tired of karma fortunes by now.rjwse@aol.com ought to be getting tired of karma fortunes by now.rjwse@aol.com ought to be getting tired of karma fortunes by now.rjwse@aol.com ought to be getting tired of karma fortunes by now.rjwse@aol.com ought to be getting tired of karma fortunes by now.rjwse@aol.com ought to be getting tired of karma fortunes by now.rjwse@aol.com ought to be getting tired of karma fortunes by now.rjwse@aol.com ought to be getting tired of karma fortunes by now.rjwse@aol.com ought to be getting tired of karma fortunes by now.rjwse@aol.com ought to be getting tired of karma fortunes by now.
 
rjwse@aol.com's Avatar
 
Posts: 348
Karma: 2581190
Join Date: Dec 2013
Location: LaVernia, Texas
Device: kindle epub readers on android
Quote:
Curious to know how many errors are reported when using epubCheck and checkbook.
Do you mean errors reported due to using classes instead of styles? Zero errors. Check book does not report errors when using classes, neither does amazon.
Attached Thumbnails
Click image for larger version

Name:	Screenshot from 2026-03-29 06-46-56.png
Views:	13
Size:	194.5 KB
ID:	222168  
rjwse@aol.com is offline   Reply With Quote
Old 03-29-2026, 02:00 PM   #8
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,808
Karma: 9501034
Join Date: Sep 2021
Location: Australia
Device: Kobo Libra 2
Quote:
Originally Posted by rjwse@aol.com View Post
Do you mean errors reported due to using classes instead of styles? Zero errors. Check book does not report errors when using classes, neither does amazon.
No, I just mean errors in general when you run epubCheck (which is an plugin) and Calibre's own Checkbook.
A couple of things don't look quite right in your screenshot.
Karellen is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Regex replace p-class in entire book AlwaysNew Editor 17 07-10-2020 09:11 AM
Regex for replacing class AlwaysNew Editor 5 06-22-2020 08:55 AM
Regex in search problems (NOT Search&Replace; the search bar) lairdb Calibre 3 03-15-2017 07:10 PM
Regex Search doesn't search all files in Edit Book GregTheGrate Editor 8 11-08-2016 12:47 AM
Help with regex POSIX class search bfollowell Sigil 7 05-21-2011 10:55 AM


All times are GMT -4. The time now is 08:12 AM.


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