首页 > 解决方案 > 我怎么能用lua做到这一点?(php 中的 preg_match())

问题描述

我需要有关 lua 中 preg_match 的帮助,我尝试了一些不同的方法。

我尝试使用string.matchand string.find,但我无法正确编写模式。

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

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

我想得到一个整数[ ]

标签: lua

解决方案


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

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

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


推荐阅读