首页
随机
登录
设置
关于DJMAX中文资料库
免责声明
DJMAX中文资料库
搜索
查看“︁模块:Regex”︁的源代码
←
模块:Regex
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
local p = {} local getArgs = require('Module:Arguments').getArgs local function showError(err) return '<span class="error">' .. tostring(err) .. '</span>' end local function performMatch(text, pattern) local result = text:match(pattern) if result == nil then error("No match found") end return result end local function performReplace(text, pattern, use) local result = text:gsub(pattern, use) if result == text then error("No use occurred") end return result end function p.match(frame) local args = getArgs(frame) local text = args[1] or '' local pattern = args[2] or '' if not text or not pattern then return showError("警告:文字或正则表达式缺失。") end local result local status, err = pcall(function() result = performMatch(text, pattern) end) if status then return result else return showError(err) end end function p.replace(frame) local args = getArgs(frame) local text = args[1] or '' local pattern = args[2] or '' local use = args[3] or '' if not text or not pattern or not use then return showError("文字、正则表达式或者使用函数错误。") end local result local status, err = pcall(function() result = performReplace(text, pattern, use) end) if status then return result else return showError(err) end end return p
该页面使用的模板:
模块:Regex/doc
(
查看源代码
)
返回
模块:Regex
。