Lua word search
snippet in lua

Lua word search

user5175

#!/usr/bin/env lua

function matchAny(str, pats)
    for w in str:gmatch('%S+') do
        if pats[w] then
            return true
        end
    end
    return false
end

pats = {
    ['MUFFIN']  = true,
    ['MOOPHIN'] = true,
    ['MUPHEN']  = true,
    ['M0FF1N']  = true,
}

print(matchAny("I want a MUFFIN", pats)) -- true
print(matchAny("I want more MUFFINs", pats)) -- false