View Single Post
Old 09-18-2010, 02:10 PM   #46
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,509
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by gwk View Post
Example 1:
Title contains: Hello world (by Smart Author)
Author contains: World series
Series contains:

Example 2:
Title contains: BookSeries 1 Hello world
Author contains: Smart Author
Series contains:
I am trying to work out how one would use cross-field templates here, other than to copy fields.

We have three things:
1) the metadata for a book. Say we are working on 'title'
2) the search expression
3) the target expression

What we do is:
book.meta('title') = re.sub(search_exp, target_exp, book.meta('title'))

We can't put a cross-field reference into search_exp, because then it won't match the metadata. We can put a cross-field reference into the target. Consider:
book.meta('series') = re.sub('', '\g<title>', book.meta('series'))
In your second example, series would now be 'BookSeries 1 Hello world'. You can now hack at it with further search/replaces.

However, I don't think that is what you really want. It seems to be that you really want to be able to say something like:
book.meta('series') = re.sub('(.*\d+) ', '\1', book.meta('title'))

Or perhaps you want both facilities?
book.meta('genre') = re.sub('(Fiction|Fantasy)', '\1 \g<#genre>', book.meta('tags'))

Do I have it right?

(Starson17, could you also answer this?)
chaley is offline   Reply With Quote