01-29-2010, 08:20 PM | #1 |
Junior Member
Posts: 2
Karma: 10
Join Date: Jan 2010
Device: Sony PRS505
|
Help with the regular expression
Hi All,
New member of the forum, so hello everyone! I thought I'd kick off with a conundrum that I'm having trouble solving. I'm a great fan of Calibre, its a great bit of software, I'm just having a little trouble configuring it to correctly identify the information from the filenames in my book collection. All my books have their filenames in this format: AuthorLastname, AuthorFirstnames - BookSeries SeriesNumber - BookTitle.FileExtension I've tweaked the regular expression (mostly by trial and error as I'm most definately not a programmer) to this: (?P<author>[^_]+) - (?P<series>[^_]+) - (?P<title>[^_]+) Now this works fine on the filename example as above, but unfortunately fails when the BookSeries and SeriesNumber parts are missing (when its a single book and not a part of a series). So for example: Pratchett, Terry - Discworld 01 - The Colour Of Magic.pdf Would work okay, but: Pratchett, Terry - Strata.pdf Wouldn't. I almost need a way to set the expression to realise that if theres only two groups to recognise that it is Author and Title and ignore the series bit. Any suggestions from the gurus? Many thanks, Mike |
01-30-2010, 10:34 AM | #2 | |
Wizard
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
|
Quote:
Code:
^((?P<author>([^\-_0-9]+)(?=\s*-\s*)(?!\s*-\s*[0-9.]+)|\b))(\s*-\s*)?((?P<series>[^0-9\-]+) (- )?(?P<series_index>[0-9.]+)\s*-\s*)?(?P<title>.+) |
|
Advert | |
|
01-30-2010, 08:46 PM | #3 |
Junior Member
Posts: 2
Karma: 10
Join Date: Jan 2010
Device: Sony PRS505
|
Hi Starson17,
Wow that works great! Many thanks, Mike |
02-22-2010, 11:39 AM | #4 | |
Junior Member
Posts: 2
Karma: 10
Join Date: Feb 2010
Device: PC
|
@ Starson17 -- That's a great expression, exactly what I was looking for. Thnx.
Quote:
|
|
02-23-2010, 06:39 AM | #5 | |
Member
Posts: 18
Karma: 10
Join Date: Dec 2008
Device: BQ
|
Quote:
I have been trying to figure out regular expression for just this, was about to quit and edit manually |
|
Advert | |
|
03-20-2010, 02:57 AM | #6 |
Junior Member
Posts: 5
Karma: 10
Join Date: Apr 2009
Device: iPhone
|
This is awesome! Thanks so much.
|
03-22-2010, 08:28 AM | #7 |
Junior Member
Posts: 5
Karma: 10
Join Date: Apr 2009
Device: iPhone
|
Actually - any chance this could be adapted so that it would still work if the series index is not included? At present, if there is no index, the series name is added to the title.
|
03-22-2010, 08:41 AM | #8 |
Wizard
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
|
Yes, but that breaks other things. The numbers of the series_index are used to help identify the series name.
|
03-22-2010, 08:57 PM | #9 |
Junior Member
Posts: 5
Karma: 10
Join Date: Apr 2009
Device: iPhone
|
Ah well, it's pretty damn good anyway. I'll just have to add in the series numbers by hand first. Thanks again!
|
03-22-2010, 11:45 PM | #10 |
Wizard
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
|
Or you can change the regex when you have books to add that don't have the series number, but have some other way to identify the series. If the series name is always in brackets, or always is after the first space-hyphen-space, then you can find it that way. I haven't found any single regex that will do all the different file naming schemes I've seen.
|
|
Similar Threads | ||||
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 |
Need Help Creating a Regular Expression | Worm | Calibre | 9 | 08-18-2010 02:20 PM |
Regular Expression Help Needed | dloyer4 | Calibre | 1 | 07-25-2010 11:37 PM |
I don't know how to use wilcards and regular expression.... | superanima | Sigil | 4 | 02-21-2010 10:42 AM |