有勇气的牛排博客

Lua正则

有勇气的牛排 364 lua 2024-09-07 21:25:45

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](


留言

专栏
文章
加入群聊