Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
Old 11-06-2010, 09:15 AM   #1
Lokro
Junior Member
Lokro began at the beginning.
 
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>[^(]+)(?:\(.*\))?
All of my files are in either two formats depending if it is a series or not

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.
Lokro is offline   Reply With Quote
Old 11-06-2010, 10:01 AM   #2
Starson17
Wizard
Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.
 
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
Quote:
Originally Posted by Lokro View Post
Looking for some help to prevent the whitespace before the Author's First name.
Your problem has nothing to do with the "crazy" regex (and I object to that characterization - I'd prefer "comprehensive" <grin>)

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.
Starson17 is offline   Reply With Quote
 
Enthusiast
Old 11-06-2010, 10:30 AM   #3
Lokro
Junior Member
Lokro began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Oct 2010
Device: Kindle
Thanks Starson for the info!
Lokro is offline   Reply With Quote
Old 11-06-2010, 10:43 AM   #4
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: 2,765
Karma: 3093505
Join Date: May 2006
Device: PocketBook 360, before it was Sony Reader, cassiopeia A-20
Quote:
Originally Posted by Lokro View Post
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>[^(]+)(?:\(.*\))?
All of my files are in either two formats depending if it is a series or not

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.
There is an option in Calibre in import/export , Adding books to swap firstname lastname.
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>.+)
kacir is offline   Reply With Quote
Old 11-06-2010, 11:05 AM   #5
Starson17
Wizard
Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.
 
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
Quote:
Originally Posted by Lokro View Post
Thanks Starson for the info!
You're welcome. That leading whitespace in the regex test has occasionally bothered me, too.
Starson17 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular Expression Help Azhad Calibre 86 09-27-2011 02:37 PM
Calibre book adding: Regular expression request... Spiffy Calibre 29 09-12-2011 10:59 AM
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


All times are GMT -4. The time now is 10:21 PM.


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