lua - 我怎么能用lua做到这一点?(php 中的 preg_match())
问题描述
我需要有关 lua 中 preg_match 的帮助,我尝试了一些不同的方法。
我尝试使用string.match
and string.find
,但我无法正确编写模式。
我在php中知道这种方式,但在lua中需要类似的方式
$s = "/testas [51]";
preg_match("#/testas [(.*)]#", $s, $out);
print_r($out);
我想得到一个整数[ ]
。
解决方案
要获取 [ ] 内的整数,请尝试以下代码:
print(string.match(s,"/testas%s+%[(%d+)%]"))
模式直接来自任务规范。我们只需要转义括号。
推荐阅读
- javascript - 如何删除每个字符后面的字符串?
- sql - 从不同数据库的 2 个表中插入 2 个表
- amazon-web-services - AWS Fargate 服务可以运行 0 个任务吗?
- python - 如何在 Python 中同时打开多个文件?
- node.js - 我们如何阻止事件循环?
- c# - Visual Studio 缩进问题
- web - Zabbix 网站监控邮件通知
- java - 我在使用 Apache POI 库 n java 读取包含大量单元格公式的 excel 文件时遇到问题
- sql - 如何使用带有 in 运算符的 oracle sql 查询的结果?
- web-scraping - Web 将 OpenWeather(一次调用)API 中的特定数据抓取到 CSV 文件中