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

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 02-09-2026, 03:09 PM   #1
CoreyEMTP
Junior Member
CoreyEMTP began at the beginning.
 
Posts: 9
Karma: 10
Join Date: Feb 2026
Device: Kobo
Question Regex help for importing books from filename

Hi All,

I'm hoping a calibre regex guru can help me out with this. I have failed, and even AI couldn't help me. Here's a filename example:

A. J. Author, Author Two - This Is the Title (2020) [1234567890123].epub

The published date and isbn are independently optional and potentially not in the filename. Here's the closest i got, which only works if the optional items are present:

(?P<author>.*?) - (?P<title>.*?) \((?P<published>\d{4})\) \[(?P<isbn>.*?)\]

The closest I got with AI was one where it would work if both optional items are present, or if only the isbn. if there is neither or only the year, it returns the entire filename minus extension as the title with no other information other than "unknown" for the author(s).

Any help for a regex that works for all four cases would be greatly appreciated!
CoreyEMTP is offline   Reply With Quote
Old 02-11-2026, 04:15 PM   #2
mitsie
Member
mitsie can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermitsie can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermitsie can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermitsie can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermitsie can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermitsie can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermitsie can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermitsie can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermitsie can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermitsie can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermitsie can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameter
 
Posts: 23
Karma: 12814
Join Date: Jun 2025
Device: PocketBook 4
Why would you need to use regex? You said the AI couldn't help you, but that was because you asked it to provide you with a straight RegEx to try to catch all. Use the AI to read the book and pull the author(s) and title out for you, with the temperature turned to 0, and you will get the answer correct every time..

It saves messing around with Regex and makes life easier

Last edited by mitsie; 02-11-2026 at 04:17 PM.
mitsie is offline   Reply With Quote
Old 02-11-2026, 05:03 PM   #3
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 22,341
Karma: 30621608
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Quote:
Originally Posted by CoreyEMTP View Post
. . . even AI couldn't help me.
If course it couldn't. AI should be regarded is as being: dumb as an ox, thick as two short planks or a brick, witless as a whelk… what ever.

Besides which there's more than one RegEx, I forget which one calibre uses.

BR
BetterRed is online now   Reply With Quote
Old 02-11-2026, 05:37 PM   #4
mitsie
Member
mitsie can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermitsie can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermitsie can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermitsie can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermitsie can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermitsie can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermitsie can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermitsie can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermitsie can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermitsie can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermitsie can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameter
 
Posts: 23
Karma: 12814
Join Date: Jun 2025
Device: PocketBook 4
Quote:
Originally Posted by BetterRed View Post
AI should be regarded is as being: dumb as an ox, thick as two short planks or a brick, witless as a whelk… what ever.
True, hitting a screw with the back of a power drill isn't the correct way to use that tool, but it might get the job done in a sloppy and inaccurate fashion.. It's the people who learn to turn the power drill around and use the trigger that get better results from the tool..
mitsie is offline   Reply With Quote
Old 02-11-2026, 06:36 PM   #5
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 50,296
Karma: 178402650
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
Quote:
Originally Posted by BetterRed View Post
Besides which there's more than one RegEx, I forget which one calibre uses.
BR
If I remember correctly, calibre uses Python's re regex library.

When I use regex101.com, for calibre, I select Python and for Sigil, I select PCRE2.
DNSB is offline   Reply With Quote
Old 02-12-2026, 12:31 AM   #6
CoreyEMTP
Junior Member
CoreyEMTP began at the beginning.
 
Posts: 9
Karma: 10
Join Date: Feb 2026
Device: Kobo
I appreciate the suggestions, and I did attempt to formulate a regex myself, but apparently there are some features of python regex that are not found in calibre's implementation. I'll run some through the regex helper, but I'm not confident.
CoreyEMTP is offline   Reply With Quote
Old 02-12-2026, 12:34 AM   #7
CoreyEMTP
Junior Member
CoreyEMTP began at the beginning.
 
Posts: 9
Karma: 10
Join Date: Feb 2026
Device: Kobo
Well, I came up with this one that works perfectly fine on regex101, using the python engine:

(?P<author>[^-]+) - (?P<title>[^(\[]+)(?: \((?P<year>\d{4})\))?(?: \[(?P<isbn>[^\]]+)\])?

Doesn't work in calibre however.
CoreyEMTP is offline   Reply With Quote
Old 02-12-2026, 02:45 PM   #8
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 31,515
Karma: 62503986
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Calibre has no field named Year or ISBN
published?
identifiers:isbn?
theducks is online now   Reply With Quote
Old 02-13-2026, 05:48 PM   #9
CoreyEMTP
Junior Member
CoreyEMTP began at the beginning.
 
Posts: 9
Karma: 10
Join Date: Feb 2026
Device: Kobo
You're absolutely right about the year, I don't know how I overlooked that. It does have a (?P<isbn>) in Calibre, however. Thanks!

Last edited by CoreyEMTP; 02-13-2026 at 05:50 PM.
CoreyEMTP is offline   Reply With Quote
Old 02-13-2026, 06:07 PM   #10
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 31,515
Karma: 62503986
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Quote:
Originally Posted by CoreyEMTP View Post


It does have a (?P<isbn>) in Calibre, however. Thanks!
Not any longer in Calibre 9
theducks is online now   Reply With Quote
Old 02-13-2026, 06:17 PM   #11
CoreyEMTP
Junior Member
CoreyEMTP began at the beginning.
 
Posts: 9
Karma: 10
Join Date: Feb 2026
Device: Kobo
For those curious or who have a similar file layout, here's the regex that finally worked:

Code:
^(?P<author>.+?)\s-\s(?P<title>(?:(?!\s[\(\[]).)+)(?:\s\((?P<published>\d{4})\))?(?:\s\[(?P<isbn>\d{10,13})\])?$
...and this is in 9.2.1, so yes it absolutely does have a (?P<isbn>)

Last edited by CoreyEMTP; 02-13-2026 at 06:19 PM. Reason: Wrong layout
CoreyEMTP is offline   Reply With Quote
Old 02-13-2026, 07:19 PM   #12
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 31,515
Karma: 62503986
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Quote:
Originally Posted by CoreyEMTP View Post
For those curious or who have a similar file layout, here's the regex that finally worked:

Code:
^(?P<author>.+?)\s-\s(?P<title>(?:(?!\s[\(\[]).)+)(?:\s\((?P<published>\d{4})\))?(?:\s\[(?P<isbn>\d{10,13})\])?$
...and this is in 9.2.1, so yes it absolutely does have a (?P<isbn>)
Then Kovid must have made a special x-reference to identifiers, as He removed the (unused) ISBN column according to the release notes.
theducks is online now   Reply With Quote
Old 02-13-2026, 08:35 PM   #13
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 50,296
Karma: 178402650
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
AFAIR, ISBNs are part of the identifiers table now.
DNSB is offline   Reply With Quote
Old 02-13-2026, 09:50 PM   #14
CoreyEMTP
Junior Member
CoreyEMTP began at the beginning.
 
Posts: 9
Karma: 10
Join Date: Feb 2026
Device: Kobo
That I don't know, but it does have the item available under the specified settings. The test box reads and displays the parts of the filename in their respective fields, including ISBN.
CoreyEMTP is offline   Reply With Quote
Old 02-13-2026, 10:42 PM   #15
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 31,515
Karma: 62503986
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
test box?

Do you mean in the MDE or details section?
Attached Thumbnails
Click image for larger version

Name:	Identifiers-ISBN.JPG
Views:	8
Size:	20.3 KB
ID:	220958  
theducks is online now   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
regex for importing books with comment Widukind Library Management 5 02-12-2021 06:13 AM
Adding Books - Filename Regex Management Paulie_D Library Management 4 05-10-2015 02:03 PM
Adding books - filename RegEx author FN (initials) LN Rob557 Library Management 8 10-16-2014 05:53 PM
regex for filename with muliple dots? (adding books) kite Library Management 5 09-28-2014 10:09 AM
Need a regex for importing books flinkdeldinky Calibre 31 10-29-2011 09:31 AM


All times are GMT -4. The time now is 05:06 PM.


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