Quote:
Originally Posted by ownedbycats
Another question regarding this one:
Code:
strcat
(
contains(f, "foo", 'foobar.png:', ''),
contains(f, "bar", 'foobar.png:', ''),
)
If a book has both "foo" and "bar", how do I get it to display foobar.png only once without using first_non_empty?

|
First, why not use first_non_empty()? It does what you seem to want with the added benefit of priority. For example
Code:
program:
f = field('#fanficcat');
strcat
(
contains(f, "Dragon Age: Origins", 'dragonageorigins.png', ''),
contains(f, "Half-Life", 'halflife.png', ''),
contains(f, "Mass Effect", 'masseffect.png', ''),
contains(f, "The Elder Scrolls", 'theelderscrolls.png', ''),
contains(f, "Pokémon", 'pokemon.png', ''),
contains(f, "Portal", 'portal.png', ''),
first_non_empty(
contains(f, "foo", 'foobar.png:', ''),
contains(f, "bar", 'foobar.png:', ''),
)
)
This solves the problem you pose without using first_non_empty():
Code:
contains(f, "^(foo|bar)$", 'foobar.png:', '')
Note the ^ and $ characters, called anchors in regex. Without anchors, contains will match the pattern anywhere in the string. For example, "bar" will match "wheelbarrow" and "Portal" will match "Starportal". My guess is that all of your comparisons should use anchors, e.g., '^Portal$'.