如何在lua中使用preg_match()函数?

我需要在lua中使用preg_match函数的帮助,我尝试了一些不同的方法。

我使用了string.matchstring.find,但我无法正确编写模式。

我知道php中的这种写法,但需要类似的方式在lua中实现

$s = "/testas [51]";
preg_match("#/testas [(.*)]#", $s, $out);
print_r($out);

我想要获取[ ]中的整数。

点赞
用户107090
用户107090

要获取[ ]内部的整数,请尝试以下代码:

print(string.match(s,"/testas%s+%[(%d+)%]"))

这个模式直接来自任务规范。我们只需要转义括号。

2019-07-13 16:16:36