Module:Switch by pattern/doc

Unlike Switch parser function, this module 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.

The module is used in Switch by pattern aka reSwitch.

Usage
Module 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
 * _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
Matches parts of the input text


 * →  (keys may include whitespace)

With unnamed parameters, returning all matches

With Lua patterns and Ustring patterns

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