A simple url matcher for Nginx-Lua, using Intel's Hyperscan (via luahs) for fast, bulk route matching, and complies with FastRoute syntax.
Use this to build your own custom URL router.
local hum = require "hs_url_match"
local obj = hum.new()
routes = {
"/hello/{name}/{today: \\d{1,2}/\\d{1,2}/\\d{2,4}}[/{lang: (?:en|fr|zh)]",
"/hello/user-{user: \d+}[/]$'
}
regexes = obj.parse(routes, {})
compiled = obj:compile(regexes)
path = "/hello/jason75/11/8/2016"
match = compiled:match(path)
--[[ Output Representation:
match = {
["path"] = "/hello/jason75/11/8/2016",
["matches"] = {
[0] = "/hello/jason75/11/8/2016",
[1] = "jason75",
[2] = "11/8/2016",
["name"] = "jason75",
["today"] = "11/8/2016",
},
["id"] = "1",
["pattern"] = "^/hello/(?P<name>[^/]+)/(?P<today>\d{1,2}/\d{1,2}/\d{2,4})(?:/\{lang: \(\?:en\|fr\|zh\))?",
}
--]]