2808 explained code solutions for 75 technologies


nginx-luaCapture string with Lua


server {
  location / {
    content_by_lua_block {
      local date = "24.02.2022"
      _, _, d, m, y = string.find(date, "(%d+).(%d+).(%d+)")
      ngx.say(m, '/', d, '/', y)
    }
  }
}ctrl + c
content_by_lua_block

nginx-lua module directive to specify block of Lua code

date = "24.02.2022"

sample string

string.find

captures found substrings and returns to a given list of variables

"(%d+).(%d+).(%d+)"

expression to capture by

ngx.say

output given text to client