View Single Post
Old 07-28-2013, 12:59 PM   #1568
JimmXinu
Plugin Developer
JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.
 
JimmXinu's Avatar
 
Posts: 7,027
Karma: 4604637
Join Date: Dec 2011
Location: Midwest USA
Device: Kobo Clara Colour running KOReader
Quote:
Originally Posted by Jade Aislin View Post
After hours of reading the regular expression site and hours of tweaking and testing different codes, I went back to the basic one I started with, at least I thought I did. Of course, it worked. So I must have changed something in it to make it work.
Yep. That's the way it goes with regular expressions. However, I don't know of a better way to give you the level of data customization you seem to want. The alternative is for you to learn python and start writing code instead. That is an option, if you like.

Quote:
Originally Posted by Jade Aislin View Post
Now I'm working on consolidating all my regex code for categories, characters, and ships. I'm trying to make one list of changes that work for all sites.

I've placed the code into the [epub] section, but I'm wondering if it would work better in the defaults or overrides section. However, I've run into a couple categories that include a comma.
I believe those are two unrelated issues. Section choice vs comma, that is.

If you plan to use the same replace_metadata for all sites and all formats, [defaults] is the most appropriate section. Then you can still put replace_metadata under specific sites if needed, or use add_to_replace_metadata in those sites.

Section precedence is:
  1. [defaults]
  2. [test1.com]
  3. [epub]
  4. [test1.com:epub]
  5. [overrides]

So you see, if you use [epub], anything site specific in [test1.com] will be 'overwritten' by [epub].

It gets more complicated when you consider add_to_* config lines.

If you put a replace_metadata in a higher precedence section([test1.com] for example), it overwrite replace_metadata from lesser precedence sections([defaults] for example).

But if you use add_to_replace_metadata instead, it does just that: adds to the replace_metadata instead of replacing it.

Code:
[defaults]
replace_metadata:
 characters=>Robert=>Bob

[test1.com]
add_to_replace_metadata:
 characters=>Susan=>Suzie
is equivalent to:
Code:
[test1.com]
replace_metadata:
 characters=>Robert=>Bob
 characters=>Susan=>Suzie
Spoiler:

Technically, the full precedence list is:
  1. [defaults]
  2. [www.test1.com]
  3. [test1.com]
  4. [epub]
  5. [www.test1.com:epub]
  6. [test1.com:epub]
  7. [overrides]
But that's a level of detail you probably don't need.


FYI, while you're consolidating, you can also apply the same regex to more than one entry at a time for example:
Code:
# instead of:
replace_metadata:
 category=>\|=> -\s
 characters=>\|=> -\s
 ships=>\|=> -\s

# use:
replace_metadata:
 category,characters,ships=>\|=> -\s
Quote:
Originally Posted by Jade Aislin View Post
Am I right in assuming that the '\,=>' should replace the commas in each individual tag? If so, where should I be placing it? Or should I be looking at the metatags that have commas in a different way?
Yes, it should. Except you don't need to escape commas in regex.

If you succeed in getting all your replace_metadata into one big list, I'd put it at the end in case any of the earlier patterns depend on commas.

If you want to allow for possible sites specific regex still, put it under overrides as an add_to_replace_metadata. That will put it at the end of any and all replace_metadata chains that get built up.

Code:
[overrides]
add_to_replace_metadata:
 category,characters,ships=>,=>\s
JimmXinu is offline