Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 03-06-2011, 12:38 PM   #1
mdibella
Groupie
mdibella can extract oil from cheesemdibella can extract oil from cheesemdibella can extract oil from cheesemdibella can extract oil from cheesemdibella can extract oil from cheesemdibella can extract oil from cheesemdibella can extract oil from cheesemdibella can extract oil from cheesemdibella can extract oil from cheese
 
Posts: 193
Karma: 1107
Join Date: Oct 2007
Device: Infinite Kindles, Occasional Sony's
Please help a poor idiot with 'regular expressions'

Here is my situation: I have a bunch of books whose author name has (as an example)

John Ringo - The Legacy of the Aldenata 5

What I want to do is move the stuff after the dash into the 'series' tag and the 'series index' tag, using 'Editing metadata in bulk' search and replace feature. Unless there's another way to do it, in which case I am *really* an idiot.

This expression: .*? -
returns the part I need to split into two pieces.

This expression: .*? - [^0-9]+
returns the number that goes into the index.


Can some genius please tell me how to construct an expression that will return the part between the dash and the number so I can put that into the series???
mdibella is offline   Reply With Quote
Old 03-06-2011, 01:24 PM   #2
Manichean
Wizard
Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.
 
Manichean's Avatar
 
Posts: 3,130
Karma: 91256
Join Date: Feb 2008
Location: Germany
Device: Cybook Gen3
I think you have misunderstood something. The expressions you gave don't "return" that part- I think you left the replace text empty and replaced everything but the part you want to get by an empty string. What you're looking for are backreferences, for example, any previously matched group (stuff in parentheses) can be referenced by its number of occurence: In your example, using the expression
Code:
(.*?) - (.*?)
with the replace string
Code:
\1
would return the author name, the replace string
Code:
\2
would return the series name and index.
What you'll need to do, then, is to do two passes: The first one inserts the series info into the series field, the second removes the series info from the author field. For the first one, use the search expression
Code:
.*? - (.*?) (\d+)
and the replace text
Code:
\1 \[\2\]
(Hint: This should, from what I remember, immediately set the series index as well- the stuff in the square brackets. Also, be careful to set your destination field to series.) For the second pass, use the search expression
Code:
(.*?) - .*?
and the replacement text
Code:
\1
(The destination field should now be authors)

Caveat: I didn't test this, so it may go horribly wrong. Test on a small sample size before going fullscale.
You may be interested in the backreferences part of the regex tutorial.
Manichean is offline   Reply With Quote
Advert
Old 03-06-2011, 02:20 PM   #3
mdibella
Groupie
mdibella can extract oil from cheesemdibella can extract oil from cheesemdibella can extract oil from cheesemdibella can extract oil from cheesemdibella can extract oil from cheesemdibella can extract oil from cheesemdibella can extract oil from cheesemdibella can extract oil from cheesemdibella can extract oil from cheese
 
Posts: 193
Karma: 1107
Join Date: Oct 2007
Device: Infinite Kindles, Occasional Sony's
Thanks so much! It didn't quite work but I figured it out.

The first pass has to use this as the replace text: \1 [\2]
mdibella is offline   Reply With Quote
Old 03-06-2011, 02:31 PM   #4
Manichean
Wizard
Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.
 
Manichean's Avatar
 
Posts: 3,130
Karma: 91256
Join Date: Feb 2008
Location: Germany
Device: Cybook Gen3
Of course, my brain was in regex mode. Sorry. Glad it worked.
Manichean is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with regular expressions Manichean Conversion 10 02-03-2011 02:27 PM
An introduction to regular expressions Manichean Conversion 0 01-26-2011 05:05 PM
Help with Regular Expressions ghostyjack Workshop 2 01-08-2010 11:04 AM
Regular Expressions help needed Phil_C Workshop 20 10-03-2009 12:14 AM
BookDesigner v5 and regular expressions ShineOn Sony Reader 11 08-25-2008 04:06 PM


All times are GMT -4. The time now is 12:38 AM.


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