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
Nginx 如何使用lua从有效uuid开始的主字符串中提取子字符串_Nginx_Lua_Openresty - Fatal编程技术网

Nginx 如何使用lua从有效uuid开始的主字符串中提取子字符串

Nginx 如何使用lua从有效uuid开始的主字符串中提取子字符串,nginx,lua,openresty,Nginx,Lua,Openresty,我有一个主字符串如下 “/tmp/xjtscpdownload/7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0/output/9999.31752806054624577114682163897525068657/” 从主字符串中,我需要从uuid部分提取一个子字符串 "/7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0/output/9999.317528060546245771146821638997525068657/" 我试过了 str

我有一个主字符串如下 “/tmp/xjtscpdownload/7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0/output/9999.31752806054624577114682163897525068657/”

从主字符串中,我需要从uuid部分提取一个子字符串

"/7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0/output/9999.317528060546245771146821638997525068657/"
我试过了
string.match(“/tmp/xjtscpdownload/7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0/output/9999.31752806054647477114682163897525068657/”,“/[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[
a-fA F0-9]{4}-[a-fA F0-9]{4}-[a-fA F0-9]/

但是,如果你想获得

“/7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0/输出/9999.31752806054624577114682163897525068657/”

或者让我们假设
7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0
output
9999.31752806054624577114682163897525068657
,这是您的模式尝试所建议的。否则,在以下解决方案中省略括号

您可以使用如下模式:

local text = "/tmp/xjtscpdownload/7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0/output/9999.317528060546245771146821638997525068657/"

print(text:match("/([%x%-]+)/([^/]+)/([^/]+)"))
“/([^/]+)/”
在两个斜杠之间捕获至少一个非斜杠字符

关于您的尝试:

不能在字符串模式中给出类似于
{4}
的计数

你必须用
%
转义
-
,因为它是一个神奇的角色

()
只捕获一个字符

请阅读以了解您的错误以及如何正确使用字符串模式。

也请尝试代码

s="/tmp/xjtscpdownload/7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0/output/9999.317528060546245771146821638997525068657/"

print(s:match("/.-/.-(/.+)$"))
它使用非贪婪匹配跳过前两个“字段”

s="/tmp/xjtscpdownload/7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0/output/9999.317528060546245771146821638997525068657/"

print(s:match("/.-/.-(/.+)$"))