Template:Switch by pattern/doc

Unlike Switch parser function, this template matches any part of the input string or any Lua pattern in the input string. It returns the first match, or all matches separated by the chosen separator.

Usage
Parameters:
 * _input input string
 * patterns return  if any of the   is found in the input string;   can be one or multiple strings separated by   (or a separator given in _sep); if unnamed parameters are used, the keys returned are their respective positions (1, 2, 3…)
 * _respectcase input string is lowercased by default, any value to avoid that
 * _returnall return the keys of all patterns that matched, separated by # or ; any value means yes
 * _returncaptures instead of keys, return captures/matches
 * _sep which separator is used to separate patterns (defaults to ); no pattern should contain this character or characters
 * _outputsep which separator to use to separate multiple keys returned when the  option is on (defaults to
 * _default which string to return if no patterns matched (defaults to empty string)

The string in  can be a Lua pattern, or a word or part of a word (always interpreted as Lua patterns!), or several such patterns separated by , as in  , which will be checked as aliases until the first match is found. (this is similar to regex matching, which is not available in Lua) Note that all named parameters will have leading and trailing whitespace removed. This not only includes (pattern) but also pattern and similar.

Examples
Matching parts of the input text:



With unnamed parameters, using  to separate patterns, and returning all matches:

Alternate template name, Lua patterns (similar, but not equal to regex patterns):





Return captures
 * →   (matched first pattern, two words)
 * →   (matched second pattern:  )
 * →    (no match, three words)