Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex ngx.re.match openresty模块处理点字符的奇怪行为_Regex_Lua_Openresty - Fatal编程技术网

Regex ngx.re.match openresty模块处理点字符的奇怪行为

Regex ngx.re.match openresty模块处理点字符的奇怪行为,regex,lua,openresty,Regex,Lua,Openresty,我在理解Lua中转义的“特殊”字符时遇到问题。 我读到点可以通过在字符前加%转义。当我尝试使用openresty和lua nginx模块时,会发生一件奇怪的事情,它匹配正则表达式ngx.re.match local path=/offers/xyz:req:test0030-10-title:co/test localregex=^/offers/([0-9a-zA-Z:%-%.]+)/test$” localmatches=ngx.re.match(path,regex)=>返回nil 我不明

我在理解Lua中转义的“特殊”字符时遇到问题。 我读到点可以通过在字符前加%转义。当我尝试使用openresty和lua nginx模块时,会发生一件奇怪的事情,它匹配正则表达式
ngx.re.match

local path=/offers/xyz:req:test0030-10-title:co/test

localregex=^/offers/([0-9a-zA-Z:%-%.]+)/test$”

localmatches=ngx.re.match(path,regex)=>返回nil

我不明白当我将
%.
移动到
%-
之前时,为什么会正确执行此操作

有人能帮我理解吗?

而Lua使用非常有限的Lua模式

在您的例子中,
%-%
创建了一个介于
%
%
之间的范围(即
%-%
匹配一个
%
),这意味着
[0-9a-zA-Z:%-%.]+
模式根本不匹配连字符

你需要

^/offers/([0-9a-zA-Z_:.-]+)/test$
                      ^^
在字符类的末尾,
-
表示一个文本
-
字符。您不需要在字符类中转义

你也可以