This seems to work. You will need to uncomment line 5 and line 14. After that you should delete line 13 and lines 1-4, which are there so I can test the template.
Code:
program:
# show = 'Criminal Minds, Law and Order';
# show = 'Pretty Little Liars, Law and Order, Supergirl';
show = 'Criminal Minds, Law and Order, Supergirl';
# show = $#show;
show1 = '^Criminal Minds$' inlist show && '^Law and Order$' inlist show;
show2 = '^Pretty Little Liars$' inlist show && '^Law and Order$' inlist show;
show3 = '^Supergirl$' inlist show && '^Law and Order$' inlist show;
output = '';
ao3tags_pair = 'Alex / Emily, Olivia / Alex';
# ao3tags_pair = $#ao3tags_pair;
for item in ao3tags_pair:
ni = '';
if show1 then
if item == "Alex / Emily" then
ni = "Emily Prentiss / Alex Cabot"
fi
fi;
if show2 then
if item == "Alex / Emily" then
ni = "Emily Fields / Alex Cabot"
fi
fi;
if show3 then
if item == "Olivia / Alex" then
ni = "Alex Danvers / Olivia Benson"
fi
fi;
if ni then
output = output & ',' & ni
else
output = output & ',' & item
fi
rof;
output = list_sort(list_remove_duplicates(output, ','), 0, ',')