Register Guidelines E-Books Today's Posts Search

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

Notices

Reply
 
Thread Tools Search this Thread
Old 04-16-2019, 01:03 PM   #1
Boats95
Junior Member
Boats95 began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Apr 2019
Device: Kindle Fire
Add Books - regular expression required

I apologize if this has been answered before, but I've searched and not found or understood the answer.

I wish to add books to calibre that are in the following format,

Lucky Shot (Joshua James).txt

but I am unable to separate title and author.

Regards

Mike
Boats95 is offline   Reply With Quote
Old 04-16-2019, 04:07 PM   #2
kacir
Wizard
kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.
 
kacir's Avatar
 
Posts: 3,463
Karma: 10684861
Join Date: May 2006
Device: PocketBook 360, before it was Sony Reader, cassiopeia A-20
Code:
(?P<title>.+) [(](?P<author>[^)]+)[)]
There are much more elaborate Regular Expressions, but this one does what you need and is simple enough to read.

Since the parenthesis is used to enclose fields like (?P<title>.+) or other groups of characters in Regular Expression I choose to "escape" the parenthesis used in filename as an author delimiter by creating character class [(] and [)]. I think you could also "escape" parenthesis by a slash like \( and \). Generally [(] is safer choice, because some programs with Regular Expressions use naked parenthesis for grouping, other escaped ones.

Here is one of more elaborate examples that would process file with name. Every time I found a file name it couldn't process I tried to refine it:
Author [(- Series #)] - Title
Series is either in [] parenthesis or ()
Code:
^(?P<author>((?!\s-\s).)+)\s-\s(?:(?:[[(]\s*)?(?P<series>.+)\s(?P<series_index>[\d\.]+)(?:\s*[])])?\s-\s)?(?P<title>[^(]+)(?:\(.*\))?
Do not worry, I wrote it, but now, after several years it is very difficult for me to read it without analysis and formatting to several lines ;-)
kacir is offline   Reply With Quote
Advert
Old 04-17-2019, 10:37 AM   #3
Boats95
Junior Member
Boats95 began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Apr 2019
Device: Kindle Fire
Thank you very much Kacir, much appreciated.

Regards

Mike
Boats95 is offline   Reply With Quote
Old 08-11-2019, 01:13 PM   #4
Thalia Helikon
Enthusiast
Thalia Helikon figured out that Keyser Söze was the Kevin Spacey character in less than 20 minutes.Thalia Helikon figured out that Keyser Söze was the Kevin Spacey character in less than 20 minutes.Thalia Helikon figured out that Keyser Söze was the Kevin Spacey character in less than 20 minutes.Thalia Helikon figured out that Keyser Söze was the Kevin Spacey character in less than 20 minutes.Thalia Helikon figured out that Keyser Söze was the Kevin Spacey character in less than 20 minutes.Thalia Helikon figured out that Keyser Söze was the Kevin Spacey character in less than 20 minutes.Thalia Helikon figured out that Keyser Söze was the Kevin Spacey character in less than 20 minutes.Thalia Helikon figured out that Keyser Söze was the Kevin Spacey character in less than 20 minutes.Thalia Helikon figured out that Keyser Söze was the Kevin Spacey character in less than 20 minutes.Thalia Helikon figured out that Keyser Söze was the Kevin Spacey character in less than 20 minutes.Thalia Helikon figured out that Keyser Söze was the Kevin Spacey character in less than 20 minutes.
 
Thalia Helikon's Avatar
 
Posts: 35
Karma: 110336
Join Date: Dec 2011
Location: Los Angeles, CA
Device: Kindle n-T, Nook Color Tablet, Nexus 6
Thumbs up Thank you!

Quote:
Originally Posted by kacir View Post
Code:
(?P<title>.+) [(](?P<author>[^)]+)[)]
Here is one of more elaborate examples that would process file with name. Every time I found a file name it couldn't process I tried to refine it:
Author [(- Series #)] - Title
Series is either in [] parenthesis or ()
Code:
^(?P<author>((?!\s-\s).)+)\s-\s(?:(?:[[(]\s*)?(?P<series>.+)\s(?P<series_index>[\d\.]+)(?:\s*[])])?\s-\s)?(?P<title>[^(]+)(?:\(.*\))?
Do not worry, I wrote it, but now, after several years it is very difficult for me to read it without analysis and formatting to several lines ;-)
this worked beautifully for me!
Thalia Helikon is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular expression to import books juliusromo Library Management 1 04-21-2012 10:43 AM
Adding books, Regular expression help please Shadewing Library Management 13 04-04-2012 05:31 AM
Regular expression to add PDFs please jgmelki Library Management 2 08-14-2011 11:58 AM
Regular Expression on adding books. Lokro Calibre 4 11-06-2010 11:05 AM
Regular Expression For Adding Books jhart711 Calibre 3 09-27-2010 06:51 AM


All times are GMT -4. The time now is 09:32 PM.


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