|07-25-2010, 07:45 PM||#1|
Join Date: Jul 2010
Regular Expression Help Needed
Importing books and I need to write a regular expression to handle the three file-name formats they're in. The file name formats are as follows:
1. author - title.type
2. author - title - series.type
3. author - title - series - series_index.type
Each category is separated by a hyphen with a space on either side. The regex needs to be able to handle the occasional hyphenated word in the title, but those hyphens are not preceded or followed by a space.
So far, I have the following regex:
(?P<author>[^-]+) - (?P<title>[^-]+) - (?P<series>[^-]+) - (?P<series_index>[^.]+)?
This works fine for case 3...though it seems to put a .0 at the end of the series number - i.e. book #3 in a series is given the series_index of 3.0 when I test the file name, but I don't know if this is a problem with my regex, or if this is simply how Calibre displays that number.
For case 1, The title is listed as "author - title" and the rest of the fields are unknown, and for case 2, the title is listed as "author - title - series" and the rest of the fields are listed as unknown.
Any one able to give me a hand with this?
|07-25-2010, 11:37 PM||#2|
Join Date: Apr 2010
Device: sony PRS-T1 and T3, Kobo Mini and Aura HD, Tablet
I do not know much about regular expressions although I generally can get them figured out if I have to.
Seems that you are beating your head against the wall with the series stuff.
I would just worry about the author-title and do a bulk download of metatdata for the series. (with the overwrite author title unchecked )
This will give you the 'official' series info etc. for 90 % of your books
A bit painful if you have already put in your own shortened series names, but must be done eventually IMO.
|Thread Tools||Search this Thread|
|Thread||Thread Starter||Forum||Replies||Last Post|
|Regular Expression Help||Azhad||Calibre||86||09-27-2011 03:37 PM|
|Regular Expression Help||smartmart||Calibre||5||10-17-2010 06:19 AM|
|Help!! Having trouble with regular expression||Partzz||Calibre||2||09-14-2010 01:32 PM|
|Need Help Creating a Regular Expression||Worm||Calibre||9||08-18-2010 02:20 PM|
|Help with the regular expression||Dysonco||Calibre||9||03-22-2010 11:45 PM|