On Wed, Mar 7, 2012 at 5:57 PM, Zoom.Quiet <
zoom...@gmail.com> wrote:
> env:
> - mac OS X 10.7.3
> - ngx_openresty/
1.0.10.48
> 需求:
> - POST 方式提交任意 url
> - 需要快速提取其中的网站根地址
> e.g:
>
http://sina.cn/news/bj/?sa=t141d48v68&vt=4> 只要:
sina.cn
>
> 经验:
> - py url.split("/")[2]
> - node.js uri.split("/")[2]
>
> 那么 openresty 只能用 ngx.re.sub 什么的进行处理?不能直接分隔提取?
>
这是一个纯 Lua 问题,呵呵,见:
http://lua-users.org/wiki/SplitJoin
不过我有计划在 ngx_lua 中实现 ngx.re.split() 函数 :)
不过,有时候用 Lua 标准的 string.match 或者 string.gmatch 函数会更方便一些。一般我会在手边放着 Lua 官方语言手册,以供随时查阅:
http://www.lua.org/manual/5.1/manual.html
Regards,
-agentzh