03-18-2012, 02:04 PM | #1 |
Enthusiast
Posts: 27
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! |
03-28-2012, 05:28 PM | #2 |
Junior Member
Posts: 3
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+)\)
Obviously this is sub-optimal, as in completely useless, so I'd be very grateful for some help. |
Advert | |
|
03-29-2012, 12:44 AM | #3 | |
Well trained by Cats
Posts: 29,798
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
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 |
|
Tags |
regex |
|
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 |