View Single Post
Old 06-05-2015, 06:07 PM   #263
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,003
Karma: 4604635
Join Date: Dec 2011
Location: Midwest USA
Device: Kobo Clara Colour running KOReader
Quote:
Originally Posted by firefoxxy View Post
And I always thought that because of the "sort ships" being on the top, it would first sort them alphabetically, and then below search for the line with Loki/Steve being corrected.

So, should I always have two lines for each ship?
sort_ships is applied after replace_metadata, regardless of order in personal.ini. That's deliberate in case you need to change the site's ship divider to '/' from something else using replace_metadata.

Rather than lines for each ship (which will only break down when you inevitably start hitting trios/quads/orgies/harems), you could have one line for each name:
Code:
replace_metadata:
 ships=>(^|/)(Steve)[^/]*(/|$)=>\1\2\3
 ships=>(^|/)(Loki)[^/]*(/|$)=>\1\2\3
 ships=>(^|/)(Lily)[^/]*(/|$)=>\1\2\3
 ships=>(^|/)(Severus)[^/]*(/|$)=>\1\2\3
## (^|/) beginning of line or a '/'
## (name) to have a \2 to save typing
## [^/]* anything except another /
## (/|$) '/' or end of line
My testing shows these work with any number of '/'s in the ship, but obviously only for the names you've added.

But it looks like what you really want is to only keep the first name of whomever. That can be done, too, but dealing with all three cases (start of line, middle and end of line) in one expression is... complex. (It has to do with overlapping matches.)
Code:
replace_metadata:
 ships=>(?:^|(?<=/))([^ ,:]+)[^/]*(?=/|$)=>\1
## (?:^|(?<=/)) non-capturing grouping of start-of-line or lookbehind matching /
## ([^ ,:]+) one or more chars until the first space, comma or colon
## [^/]* zero or more chars until /
## (?=/|$) lookahead matching / or end-of-line
This also handles cases with : or , after the first name, like Thor: thundergod/Darcy, snarky intern. But it won't work well if you get Doctor Quinn/Doctor McCoy--that will end up as Doctor/Doctor.
JimmXinu is offline   Reply With Quote