Aller au contenu

Module:Regexp

De Poképédia

La documentation pour ce module peut être créée à Module:Regexp/doc

local p = {}

function p.replace(frame)
	local s = frame.args[1]
	local pattern = frame.args[2]
	local replace = frame.args[3]
	
	if not s then s = "" else s = frame:preprocess(s) end
	if not pattern then pattern = "" else pattern = mw.ustring.gsub(pattern, "<nowiki>(.-)</nowiki>", "%1") end
	if not replace then replace = "" else replace = mw.ustring.gsub(replace, "<nowiki>(.-)</nowiki>", "%1") end
	
	local ans = mw.ustring.gsub(s, pattern, replace)
	return ans
end

function p.retirerparentheses(frame)
	frame.args[2] = " *%(.*%)"
	frame.args[3] = ""
	return p.replace(frame)
end

return p