From English Wikipedia @ Freddythechick
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