function getKeywords(text) if not text then return {} end local s = tostring(text):lower() local keywords = {} for code in s:gmatch("[%a%d]+%-[%a%d]+") do keywords[code] = true end for code in s:gmatch("%a+%d+") do keywords[code] = true end for zh in s:gmatch("[\128-\255]+") do local cleanZh = zh:gsub("站台", ""):gsub("轨道", ""):gsub("号", ""):gsub("线", "") if cleanZh and cleanZh ~= "" then keywords[cleanZh] = true end end local list = {} for k, _ in pairs(keywords) do table.insert(list, k) end return list end local function test(a, b) local k1 = getKeywords(a) local k2 = getKeywords(b) local match = false for _, w1 in ipairs(k1) do for _, w2 in ipairs(k2) do if w1 == w2 or w1:find(w2, 1, true) or w2:find(w1, 1, true) then match = true break end end end print(a .. " vs " .. b .. " -> " .. tostring(match)) print(" K1: " .. table.concat(k1, ", ")) print(" K2: " .. table.concat(k2, ", ")) end test("CE-03 (桃园)", "桃园") test("CE-04", "CE-04 [西门]") test("CRH-01", "CRH-01 南山线") test("南山线", "南山") test("???", "Unknown")