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

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

Notices

Reply
 
Thread Tools Search this Thread
Old 03-18-2012, 02:04 PM   #1
charlweed
Member
charlweed began at the beginning.
 
Posts: 14
Karma: 30
Join Date: Jul 2011
Device: none
Replace field with match or empty string?

I want to “replace” a field with a string from the title is it is found, or an empty string if it is not.
I currently have mixed titles like:

Anne McCaffrey - Pern 10 - The Renegades of Pern
Generation Warriors
The Mystery of Ireta: Dinosaur Planet & Dinosaur Planet Survivors
Anne McCaffrey - Tsw 7 - Ship That Returned

I want to pick out “Pern 10” from the first example, and “Tsw 7” from the fourth example, and write them to the series field. How can I do this?

My current problem is that if there is no match for my group expression, the UI reports an “unmatched group” error, and refuses to proceed.
So how can I create a group that “always matches” but contains an empty string if it’s really not there?
Here is my current, erroneous expression,

(((P<author>[^-]*?)- )?((?P<series>\w+)\W*(?P<series_index>\d*)\s-))?(?P<title>.*)

The only field I want at the moment is \g<series>

Thanks!
charlweed is offline   Reply With Quote
Old 03-28-2012, 05:28 PM   #2
M. Northstar
Junior Member
M. Northstar began at the beginning.
 
M. Northstar's Avatar
 
Posts: 1
Karma: 10
Join Date: Mar 2012
Location: Sweden
Device: Smart Phone
I joined the forums to ask about exactly this same problem, except that I'm using the Find&replace feature of the metadata editor... and if it doesn't find my group in a filename it returns the entire name instead of an empty string; i.e. my regex of
Code:
.*? \((.+?)-(\d+)\)
Applied to
  • The Yellow Admiral
  • Master and Commander (aubrey-1)
  • Heart of the West
returns:
  • The Yellow Admiral
  • aubrey [1]
  • Heart of the West
as the series.

Obviously this is sub-optimal, as in completely useless, so I'd be very grateful for some help.
M. Northstar is offline   Reply With Quote
Old 03-29-2012, 12:44 AM   #3
theducks
Grand Sorcerer
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 14,096
Karma: 5468860
Join Date: Aug 2009
Location: The (original) Silicon Valley, USA
Device: Galaxy Tab 2, Astak Pocket Pro, K4NT
Quote:
Originally Posted by M. Northstar View Post
I joined the forums to ask about exactly this same problem, except that I'm using the Find&replace feature of the metadata editor... and if it doesn't find my group in a filename it returns the entire name instead of an empty string; i.e. my regex of
Code:
.*? \((.+?)-(\d+)\)
Applied to
  • The Yellow Admiral
  • Master and Commander (aubrey-1)
  • Heart of the West
returns:
  • The Yellow Admiral
  • aubrey [1]
  • Heart of the West
as the series.

Obviously this is sub-optimal, as in completely useless, so I'd be very grateful for some help.
Series is a PITA
You need to do it as 3 passes.
Pass 1 sets JUST the series name
Pass 2 sets the Series_index

Pass 3 consumes the Series and Series index, leaving the remainder in the title
theducks is online now   Reply With Quote
Reply

Tags
regex

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Regex - replace only part of a string - how? flameproof Sigil 11 02-23-2012 04:43 AM
Metadata Search & Replace - when it doesn't match Aldebaranian Library Management 4 09-28-2011 11:35 AM
Variable Search, Replace & Transfer to a new field flopis Library Management 10 03-09-2011 11:41 AM
Find and replace string with wildcard jhempel24 Sigil 15 11-12-2010 01:50 PM
How to make Author field empty? khutch Calibre 1 08-14-2009 02:12 PM


All times are GMT -4. The time now is 01:57 AM.


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