lua自己实现非标准regex
/
begidx, endidx, substr...
string.find
(s, pattern [, init [, plain]])
功能:查找目标模板在给定字符串中出现的位置
参数:
s 原字符串
pattern 模式串
init 开始搜索的位置
plain 默认为flase,传入true关闭模式匹配简单查找子串
返回:
begidx 开始的位置 未找到就为nil
endidx 结束的位置
capturestr1 如果有捕获会在这里
capturestr2
eg:
查找位置
local s = "hello, world"
local i, j = string.find(s, "hello")
print(i, j) ->1 5
查找并捕获
local i, j, cap1, cap2 = string.find(s, "(%w+)[,%s]+(%w+)")
print(i, j, cap1, cap2) -> 1 12 hello world
换行符出现的所有位置
local t = {}