Template:Strmatch/doc

ShoutWiki — express yourself and be heard!
Jump to navigation Jump to search
Template:Strmatch invokes Module:String using Lua.

A substring from the string that matches a specified pattern

Use[edit source]

{{Strmatch|string|pattern|start=index|match=index|plain=Boolean|nomatch=return}}

string
the string to search
pattern
the substring to find within the string
start
(optional, default: 1) the position of the first character to begin searching; an integer between 1 and the length of the string; negative numbers specify a position from the end of the string
match
(optional, default: 1) the pattern match to return in case multiple matches are found; negative numbers count backward from the last match
plain
(optional, default: false) pattern should be considered literal text rather than a Lua pattern expression
nomatch
(optional) a value to return instead of generating an error if no match is found

Examples[edit source]

{{Strmatch|abc3c%d|c%d}}

produces

c3


{{Strmatch|abc3c%d|c%d|plain=true}}

produces

c%d


{{Strmatch|abc3c%d|x}}

produces

String Module Error: Match not found


{{Strmatch|abc3c%d|x|nomatch=Not found}}

produces

Not found


z{{Strmatch|abc3c%d|x|nomatch=}}z

produces

zz