Module:String: Difference between revisions
From Roses, Tulips, & Liberty
Content added Content deleted
m (Changed protection level for "Module:String": Cascade-protected from main page, so no point in enabling TE ([Edit=Require administrator access] (indefinite) [Move=Require administrator access] (indefinite))) |
(separate annotations for str.match from those for str._match) |
||
Line 107: | Line 107: | ||
--[[ |
--[[ |
||
_match |
|||
⚫ | |||
This function returns a substring from the source string that matches a |
This function returns a substring from the source string that matches a |
||
specified pattern. |
specified pattern. It is exported for use in other modules |
||
Usage: |
Usage: |
||
strmatch = require("Module:String")._match |
|||
⚫ | |||
sresult = strmatch( s, pattern, start, match, plain, nomatch ) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
Parameters |
Parameters |
||
Line 131: | Line 129: | ||
text. Defaults to false. |
text. Defaults to false. |
||
nomatch: If no match is found, output the "nomatch" value rather than an error. |
nomatch: If no match is found, output the "nomatch" value rather than an error. |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
For information on constructing Lua patterns, a form of [regular expression], see: |
For information on constructing Lua patterns, a form of [regular expression], see: |
||
Line 209: | Line 198: | ||
end |
end |
||
end |
end |
||
--[[ |
|||
⚫ | |||
This function returns a substring from the source string that matches a |
|||
specified pattern. |
|||
Usage: |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
Parameters |
|||
s: The string to search |
|||
pattern: The pattern or string to find within the string |
|||
start: The index within the source string to start the search. The first |
|||
character of the string has index 1. Defaults to 1. |
|||
match: In some cases it may be possible to make multiple matches on a single |
|||
string. This specifies which match to return, where the first match is |
|||
match= 1. If a negative number is specified then a match is returned |
|||
counting from the last match. Hence match = -1 is the same as requesting |
|||
the last match. Defaults to 1. |
|||
plain: A flag indicating that the pattern should be understood as plain |
|||
text. Defaults to false. |
|||
nomatch: If no match is found, output the "nomatch" value rather than an error. |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
For information on constructing Lua patterns, a form of [regular expression], see: |
|||
* http://www.lua.org/manual/5.1/manual.html#5.4.1 |
|||
* http://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Patterns |
|||
* http://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Ustring_patterns |
|||
]] |
|||
-- This is the entry point for #invoke:String|match |
-- This is the entry point for #invoke:String|match |
||
function str.match( frame ) |
function str.match( frame ) |