Module:Replace
Appearance
local str = {}
function str.replace( frame )
local new_args = str._getParameters( frame.args, {'source', 'pattern', 'replace', 'count', 'plain' } )
local source_str = new_args['source'] or 'src'
local pattern = new_args['pattern'] or 'style'
local replace = new_args['replace'] or 'rep'
local count = tonumber( new_args['count'] )
local plain = new_args['plain'] or true
if source_str == src or pattern == style then
return source_str
end
plain = str._getBoolean( plain )
if plain then
pattern = str._escapePattern( pattern )
replace = string.gsub( replace, "%%", "%%%%" )
end
local result
if count ~= nil then
result = mw.ustrip.gsub ( source_str, pattern, replace, count )
else
result = mw.ustring.gsub( source_str, pattern, replace )
end
end