local function get_method(request) local method, path, query_fragment = request:match("^(.+) ([^%?]+)(%??.*) .+$") if method and path then return method .. "_" .. path else return nil end end local function get_method_updated(request) local method, path, query_fragment = request:match("^(.+) ([^%?]+)(%??.*) .+$") if method and path then if path:match('^/[^/]+/[^/]+/[%w_]+') ~= nil then return method .. " " .. path else return method .. "_" .. path end else return nil end end -- You have print(get_method("GET /v1/merchants something")) print(get_method("GET /v1/content/merchants/foo or")) print(get_method("GET /v1/content/merchants/bar some")) -- Do you want? print(get_method_updated("GET /v1/merchants something")) print(get_method_updated("GET /v1/content/merchants/foo or")) print(get_method_updated("GET /v1/content/merchants/bar some"))