View Single Post
Old 08-26-2012, 07:51 AM   #8
JustForFun
Enthusiast
JustForFun has learned how to read e-booksJustForFun has learned how to read e-booksJustForFun has learned how to read e-booksJustForFun has learned how to read e-booksJustForFun has learned how to read e-booksJustForFun has learned how to read e-booksJustForFun has learned how to read e-books
 
Posts: 30
Karma: 752
Join Date: Nov 2010
Device: PB360
How about this:
Code:
(?P<title>[^-]+)\s*-\s*(?P<author>[^-]+)(\s*-\s*(?P<series>[^0-9-]+)(\s+|$)(?P<series_index>[0-9]+)?|$)
It matches both given examples in the test of the preferences dialog. It also matches a series without a series index.

I'm not sure why, but using an '?' at the end of the expression to make the series part optional didn't work for me, so the expression tests for an optional series or the end of the string. Additionally the expression tries to avoid to add a space to the end of the series name if there is a series index present.

EDIT:
With a more recent calibre version using '?' for the optional series seems to work. A somewhat refined version which doesn't add a space at the end of the title:
Code:
(?P<title>[^-]+[^\s])\s*-\s*(?P<author>[^-]+)(\s*-\s*(?P<series>[^0-9-]+)($|(\s+(?P<series_index>[0-9]+))))?
Interestingly authors seems to be processed further as it does not have a space at the end which the expression would leave there.

Last edited by JustForFun; 08-26-2012 at 10:05 AM. Reason: Refinement
JustForFun is offline   Reply With Quote