Quote:
Originally Posted by JimmXinu
This feels really familiar. I'm sure I've done something similar before, but I don't immediately find it either.
Detecting and moving one name out of a list to the front isn't difficult. Doing it while preserving the delimiters between names when the target name can be first, middle or last is a little trickier.
Here's what I've come up with using named regexp grouping for clarity:
Code:
# assume leading delim, otherwise, already first
ships=>^(?P<pre>.*?)(?P<delim>[ ]*(&|/)[ ]*)(?P<first>Rose Tyler)(?P<post>.*)$=>\g<first>\g<delim>\g<pre>\g<post>
- This assumes that you know what delimiters can exist between ships. [ ]*(&|/)[ ]* should be pretty universal.
- This also assumes that each ship will only have one kind of delimiter--eg, you won't have A & B / C in one ships entry.
- As the comment says, the regexp assumes a delimiter before the desired first name, otherwise it's already first and no change is needed.
- Everything before the first delimiter and the desired first name is grouped in pre, the delimiter in delim, desired first name in first, and everything after (including delimiters) in post.
- Rearrange to be first, delim, pre, then post.
- pre is assumed to always exist, but post could be empty. If it's not, it starts with a delimiter.
- sort_ships is applied before replace_metadata, so you can do both if you want.
If you get the wild idea to apply more than one of these, remember that replace_metadata lines are applied in order, which in this case means the last line 'wins'. See INI-File wiki and add_to_keyword in particular if you try to get fancy with [defaults] vs different sites.
Example:
Code:
ships=>^(?P<pre>.*?)(?P<delim>[ ]*(&|/)[ ]*)(?P<first>Rose Tyler)(?P<post>.*)$=>\g<first>\g<delim>\g<pre>\g<post>
ships=>^(?P<pre>.*?)(?P<delim>[ ]*(&|/)[ ]*)(?P<first>Jack Harkness)(?P<post>.*)$=>\g<first>\g<delim>\g<pre>\g<post>
# Jack ends up before Rose when both appear.
|
This might be useful to add to MetadataManagement page