Lua正则
知止自律打卡-微信小程序APP
一款微信自律打卡小程序,支持自定义打卡项目、习惯记录、项目日记、专注计时与数据统计。自律打卡、学习打卡、读书打卡、健身打卡、运动打卡、减肥打卡、戒色打卡、养生打卡、戒烟、戒酒、戒熬夜等多种场景。万能打卡模板自由创建。可自定义每日打卡目标,记录习惯连续天数,可视化追踪成长进度。
了解产品详情 →
微信搜索「知止自律打卡」
lua正则判断特定字符串是否在文本中
local text = "Hello, world!"
local pattern = "world" -- 正则表达式模式
-- 使用 string.find
if string.find(text, pattern) then
print("字符串包含指定的模式")
else
print("字符串不包含指定的模式")
end
-- 使用 string.match
if string.match(text, pattern) then
print("字符串包含指定的模式")
else
print("字符串不包含指定的模式")
end
现在要判断 .php、.asp、select是否在uri中
local uri = "/path/to/file.php?query=select%20*%20from%20users"
-- 定义要匹配的模式
local patterns = { "%.php", "%.asp", "select" }
-- 检查 URI 是否包含任意一个模式
local function containsPattern(uri, patterns)
for _, pattern in ipairs(patterns) do
if string.find(uri, pattern) then
return true
end
end
return false
end
-- 使用函数进行检查
if containsPattern(uri, patterns) then
print("URI 包含指定的模式")
else
print("URI 不包含指定的模式")
end
有勇气的牛排
[https://www.couragesteak.com/article/475](
标签: