11-06-2010, 09:15 AM | #1 |
Junior Member
Posts: 4
Karma: 10
Join Date: Oct 2010
Device: Kindle
|
Regular Expression on adding books.
I did a lot of searching and couldn't find the answer. I found a regular expression here but I have a small problem with it.
Now I don't think I need anything this crazy. Code:
(?P<author>((?!\s-\s).)+)\s-\s(?:(?:\[\s*)?(?P<series>.+)\s(?P<series_index>\d+)(?:\s*\])?\s-\s)?(?P<title>[^(]+)(?:\(.*\))? authorlastname, authorfirstname - Seriesname 01 - Title.extension or authorlastname, authorfirstname - Title.extension The above Regular Expression is picking up everything fine but it is adding a whitespace character to Author First name. I can rename my files authorlastname,authorfirstname and it will work fine but I have a good number of files and really don't want to go through and rename them all. Looking for some help to prevent the whitespace before the Author's First name. |
11-06-2010, 10:01 AM | #2 | |
Wizard
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
|
Quote:
Regex can only pull the entire author name, not the first or last name parts separately. There's no change you can make to the regex that will do what you want. However, after the whole string is pulled, then Calibre can swap the LN, FN format to FN LN, and it does that when you tell it to by setting the swap option in Preferences. The "whitespace" you are worried about arises during that swap, and it's not real - you see it only in the "test." Calibre strips the leading whitespace before it uses the name. (I'll test and verify that in a moment - I'm in the middle of an install and can't run Calibre until after I reboot, but don't want to lose this typing.) Edit: Yes, it stripped the leading whitespace. Last edited by Starson17; 11-06-2010 at 10:24 AM. |
|
Advert | |
|
11-06-2010, 10:30 AM | #3 |
Junior Member
Posts: 4
Karma: 10
Join Date: Oct 2010
Device: Kindle
|
Thanks Starson for the info!
|
11-06-2010, 10:43 AM | #4 | |
Wizard
Posts: 3,447
Karma: 10484861
Join Date: May 2006
Device: PocketBook 360, before it was Sony Reader, cassiopeia A-20
|
Quote:
when the book is firstname lastname - series 01 - title you leave it unchecked, when the book filename is lastname, firstname - series 01 - title you check it. Another option is to import everything with the option unchecked and then, at the end of the day do - select all imported books - start bulk edit - start experimental search and replace - search field author - search for ([^ ]+), (.+) - replace with \2 \1 I use this import regular expression Code:
(?P<author>[^-]+)( - (\[|\()?(?P<series>[^-]+)(\[| |\()+(?P<series_index>[0-9]+)(\]|\))?)? - (?P<title>.+) |
|
11-06-2010, 11:05 AM | #5 |
Wizard
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
|
|
Advert | |
|
Thread Tools | Search this Thread |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Calibre book adding: Regular expression request... | Spiffy | Calibre | 34 | 01-19-2016 01:03 PM |
Regular Expression Help | Azhad | Calibre | 86 | 09-27-2011 02:37 PM |
Regular Expression For Adding Books | jhart711 | Calibre | 3 | 09-27-2010 06:51 AM |
Helping importing books using regular expression | askyn | Calibre | 4 | 05-08-2010 01:06 AM |
Help with the regular expression | Dysonco | Calibre | 9 | 03-22-2010 10:45 PM |