![]() |
#1 |
Groupie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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??? |
![]() |
![]() |
![]() |
#2 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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:
(.*?) - (.*?) Code:
\1 Code:
\2 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+) Code:
\1 \[\2\] Code:
(.*?) - .*? Code:
\1 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. |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Groupie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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] |
![]() |
![]() |
![]() |
#4 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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.
|
![]() |
![]() |
![]() |
Thread Tools | Search this Thread |
|
![]() |
||||
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 |