Editing Module:String
From MINR.ORG WIKI
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 113: | Line 113: | ||
Usage: | Usage: | ||
− | {{#invoke:String|match|source_string|pattern_string|start_index|match_number|plain_flag | + | {{#invoke:String|match|source_string|pattern_string|start_index|match_number|plain_flag}} |
OR | OR | ||
{{#invoke:String|pos|s=source_string|pattern=pattern_string|start=start_index | {{#invoke:String|pos|s=source_string|pattern=pattern_string|start=start_index | ||
− | |match=match_number|plain=plain_flag | + | |match=match_number|plain=plain_flag}} |
Parameters | Parameters | ||
Line 128: | Line 128: | ||
counting from the last match. Hence match = -1 is the same as requesting | counting from the last match. Hence match = -1 is the same as requesting | ||
the last match. Defaults to 1. | the last match. Defaults to 1. | ||
− | + | plain_flag: A flag indicating that the pattern should be understood as plain | |
text. Defaults to false. | text. Defaults to false. | ||
− | |||
If invoked using named parameters, Mediawiki will automatically remove any leading or | If invoked using named parameters, Mediawiki will automatically remove any leading or | ||
Line 149: | Line 148: | ||
]] | ]] | ||
function str.match( frame ) | function str.match( frame ) | ||
− | local new_args = str._getParameters( frame.args, {'s', 'pattern', 'start', 'match', 'plain | + | local new_args = str._getParameters( frame.args, {'s', 'pattern', 'start', 'match', 'plain'} ); |
local s = new_args['s'] or ''; | local s = new_args['s'] or ''; | ||
local start = tonumber( new_args['start'] ) or 1; | local start = tonumber( new_args['start'] ) or 1; | ||
Line 155: | Line 154: | ||
local pattern = new_args['pattern'] or ''; | local pattern = new_args['pattern'] or ''; | ||
local match_index = math.floor( tonumber(new_args['match']) or 1 ); | local match_index = math.floor( tonumber(new_args['match']) or 1 ); | ||
− | |||
if s == '' then | if s == '' then | ||
Line 206: | Line 204: | ||
if result == nil then | if result == nil then | ||
− | + | return str._error( 'Match not found' ); | |
− | |||
− | |||
− | |||
− | |||
else | else | ||
return result; | return result; |