Module:Sandbox/BrownHairedGirl/sandbox

From English Wikipedia @ Freddythechick

This is the current revision of this page, as edited by imported>BrownHairedGirl at 02:19, 28 September 2019 (tweak). The present address (URL) is a permanent link to this version.

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
local p = {}

function patternSearchEncode(s)
	return mw.ustring.gsub(s, "([%W])", "%%%1")
end


function p.main(frame)

local testProvince = "the Northwest Territories"
local pn = "Category:Ordovician Northwest Territories"

local retval =""

if (mw.ustring.match(testProvince, "^[tT]he ") ~= nil) then
	retval = retval .. "\npn = '" .. pn .. "'"
	retval = retval .. "\ntestProvince = '" .. testProvince .. "'"
	local testProvinceStripped = mw.ustring.gsub(testProvince, "^[tT]he ", "", 1)
	retval = retval .. "\ntestProvinceStripped = '" .. testProvinceStripped .. "'"
	local testProvinceStrippedEncoded = patternSearchEncode(testProvinceStripped)
	retval = retval .. "\ntest pattern without leading definite article, i.e. '" .. testProvinceStrippedEncoded .. "' ? "
	if (mw.ustring.match(pn, "[^%w]" .. testProvinceStrippedEncoded .. "[^%w]")  ~= nil)
	or (mw.ustring.match(pn, "^" .. testProvinceStrippedEncoded .. "[^%w]")  ~= nil)
	or (mw.ustring.match(pn, "[^%w]" .. testProvinceStrippedEncoded .. "$")  ~= nil)
	or (mw.ustring.match(pn, "^" .. testProvinceStrippedEncoded .. "$")  ~= nil) then
		retval = retval .. "Yes"
	else
		retval = retval ..  "No"
	end
		return retval
end

end
return p