Module:ISO 3166/sandbox: Difference between revisions

Content deleted Content added
expand accents, add to remove
fix replace order, add accented characters
Line 93:
"PROVINCE OF","PROVINCE","TERRITORY","COUNTY","CITY OF"
}
local patterns = {["(%a)%.(%a)%.",".+:"]="",["|.+"]="",["%(.-%)"]="", -- patterns to follow (order may matter)
"%..*","^THE ","%_","%-","%d%d?%d?PX"
}
local replacements = {["(%a)%.(%a)%."]="%1%2", -- Replacements for patterns above (order does not matter)
[".+:"]="",["|.+"]="",["%(.-%)"]="",
["%..*"]="",["^THE "]="",["%_"]=" ",["%-"]=" ",
["%d%d?%d?PX"]="",
Line 103 ⟶ 107:
text = mw.ustring.gsub(text,"[À-Ż]",accents) -- Deaccent
for pattern_,valuepattern in pairsipairs(patterns) do -- Follow patterns
local value = replacements[pattern]
text = mw.ustring.gsub(text,pattern,value)
end
Line 113 ⟶ 118:
text = mw.ustring.gsub(text,"%W","") -- Remove non alpha-numeric
return mw.text.trim(text)
end