Regex 用正则表达式检测句子末尾的单词
我从正则表达式开始。我的字符串可以看起来像Regex 用正则表达式检测句子末尾的单词,regex,linux,nginx,lua,Regex,Linux,Nginx,Lua,我从正则表达式开始。我的字符串可以看起来像nxs\u-flo.nexus或127.0.0.1或nxs\u-flo.nexus.com 我只想过滤nxs\u flo.nexus类型的字符串。所以我想测试我的字符串中是否有.nexus,它是否在字符串的末尾 下面是我对过滤器所做的操作,但我看不到如何对过滤器.nexus执行此操作,最后是: if ngx.var.host:match("(.-)%.") == nil then 或者,此选项用于检测.nexus,但不起作用: if ngx.var.h
nxs\u-flo.nexus
或127.0.0.1
或nxs\u-flo.nexus.com
我只想过滤nxs\u flo.nexus
类型的字符串。所以我想测试我的字符串中是否有.nexus
,它是否在字符串的末尾
下面是我对过滤器
所做的操作,但我看不到如何对过滤器.nexus
执行此操作,最后是:
if ngx.var.host:match("(.-)%.") == nil then
或者,此选项用于检测.nexus
,但不起作用:
if ngx.var.host:match("(.*).nexus") == nil then
你可以用
local host = [[nxs_flo.nexus]]
if host:match("%.nexus$") == nil then
print("No '.nexus' at the end of the string!")
else
print("There is '.nexus' at the end of the string!")
end
-- => There is '.nexus' at the end of the string!
看
模式匹配:
-文字%。
字符
-nexus子字符串nexus
-字符串结束$
ngx.var.host:match((.*).nexus$”==nil
我不知道lua或nginx正则表达式的实现,但您可能需要编写%。而不是匹配角色。而不是任何字符