fork(5) download
  1. local function get_method(request)
  2. local method, path, query_fragment = request:match("^(.+) ([^%?]+)(%??.*) .+$")
  3. if method and path then
  4. return method .. "_" .. path
  5. else
  6. return nil
  7. end
  8. end
  9. local function get_method_updated(request)
  10. local method, path, query_fragment = request:match("^(.+) ([^%?]+)(%??.*) .+$")
  11. if method and path then
  12. if path:match('^/[^/]+/[^/]+/[%w_]+') ~= nil then
  13. return method .. " " .. path
  14. else
  15. return method .. "_" .. path
  16. end
  17. else
  18. return nil
  19. end
  20. end
  21. -- You have
  22. print(get_method("GET /v1/merchants something"))
  23. print(get_method("GET /v1/content/merchants/foo or"))
  24. print(get_method("GET /v1/content/merchants/bar some"))
  25. -- Do you want?
  26. print(get_method_updated("GET /v1/merchants something"))
  27. print(get_method_updated("GET /v1/content/merchants/foo or"))
  28. print(get_method_updated("GET /v1/content/merchants/bar some"))
  29.  
Success #stdin #stdout 0s 2788KB
stdin
Standard input is empty
stdout
GET_/v1/merchants
GET_/v1/content/merchants/foo
GET_/v1/content/merchants/bar
GET_/v1/merchants
GET /v1/content/merchants/foo
GET /v1/content/merchants/bar