[go: up one dir, main page]

Prijeđi na sadržaj

Modul:Zamijeni tekst

Izvor: Wikipedija
local p = {}

function literalize(str)
    return str:gsub("[%(%)%.%%%+%-%*%?%[%]%^%$]", function(c) return "%" .. c end)
end

function p.main(frame)
	local text = mw.getCurrentFrame():getParent().args[1]
    local find = mw.getCurrentFrame():getParent().args[2]
    local replace = mw.getCurrentFrame():getParent().args[3]
    
    local allfinds = Split(find, ",")
    
	for k,v in pairs(allfinds) do
		text = string.gsub(text, literalize(v), replace)
	end
	
	return text
end

function Split(s, delimiter)
    result = {};
    for match in (s..delimiter):gmatch("(.-)"..delimiter) do
        table.insert(result, match);
    end
    return result;
end

return p