View Single Post
Old 11-02-2018, 01:49 PM   #3042
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,025
Karma: 4604635
Join Date: Dec 2011
Location: Midwest USA
Device: Kobo Clara Colour running KOReader
Quote:
Originally Posted by Tanjamuse View Post
How do I swap persons in a relationship
The literal answer to your question, ie how to reverse a two person ship (without regard to content) with possible separators '\', '/' or '§', while preserving separator whitespace is surprisingly complicated to get right:

Code:
add_to_replace_metadata:
 ships=>^(.+?)([ ]*[§/\\][ ]*)(.+)$=>\3\2\1
# note that \ must be escaped to \\ in the regex part.
If you only want to change those specific ships, the most straightforward way is to just do those exact strings:

Code:
add_to_replace_metadata:
 ships=>Jack Sparrow § Elizabeth Swann=>Elizabeth Swann § Jack Sparrow
 ships=>Will Turner/Elizabeth Swann=>Elizabeth Swann/Will Turner
However, if what you really want is all your ships sorted alphabetically (even when more than two), while preserving the separator character and normalizing separator spacing, you can add turn on sort_ships the '§' separator to sort_ships_splits.

Code:
sort_ships:true
## default sort_ships_splits already does \ and &, but it removes spaces around /
sort_ships_splits:
 [ ]*/[ ]*=>\s/\s
 [ ]*&[ ]*=>\s&\s
 [ ]*§[ ]*=>\s§\s
 [ ]*\\[ ]*=>\s\\s
Two caveats:
- With Win10 CLI, putting '§' in personal.ini caused an error reading the config file.
- As I recall, ships with more than 2 names and different separators may cause undefined ordering.
JimmXinu is offline   Reply With Quote