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子字符串
  • $
    -字符串结束

试着逃出这个陷阱。在第二个示例中,也在末尾附加一个$,以仅匹配line@AlexanderDaum:像这样:
ngx.var.host:match((.*).nexus$”==nil
我不知道lua或nginx正则表达式的实现,但您可能需要编写%。而不是匹配角色。而不是任何字符