查看“模块:字符串处理”的源代码
←
模块:字符串处理
跳转到导航
跳转到搜索
因为以下原因,你没有权限 编辑此页:
你请求的操作仅限属于此用户组的用户执行:
用户
你可以查看和复制此页面的源代码。
require('strict') local frame = mw.getCurrentFrame() local p = { } local function explode(s, delimiter) local result = {} local str = s:gsub(delimiter, '|') for match in str:gmatch('[^|]+') do table.insert(result, match) end return result end function p.replace(frame) local s, pattern, repl, n, mode s = frame.args[1] pattern = frame.args[2] repl = frame.args[3] if string.len(frame.args[4]) > 0 then n = tonumber(frame.args[4]) mode = frame.args[5] if mode == "except" then s = s:gsub(pattern, repl) pattern = frame.args[3] repl = frame.args[2] end end local str = s:gsub(pattern, repl, n) return str end function p.dateprocess(frame) local output = '' for i, value in ipairs(explode(frame.args[1], '<br>')) do local date = {value:match('(%d*)(%d%d%d%d%-[%dx]+)')} if date[1] == '' and ({value:match('(%d*)(%d%d%d%d%-%d+%-[%dx]+)')})[2] then date = value:gsub('(%d%d%d%d)%-(%d+)%-([%dx]+)', '%1 年 %2 月 %3 日') elseif date[1] == '' and date[2] then date = value:gsub('(%d%d%d%d)%-(%d+)', '%1 年 %2 月') elseif value:match('^%d%d%d%d') then date = value:gsub('(%d%d%d%d)', '%1 年') else date = value end output = output..date..'<br>' end output = output:gsub('<br>$','') return output end function p.preprocess(frame) for i, value in ipairs(explode(frame.args[1], '<br>')) do local date = {value:match('(%d*)(%d%d%d%d%-%d+)')} if date[1] == '' and date[2] then return 1 elseif value:match('^%d%d%d%d') then return 1 end end return 0 end return p
此页使用的模板:
手动:字符串处理/doc
(
查看源代码
)
返回
模块:字符串处理
。
导航菜单
个人工具
登录
命名空间
模块
讨论
English
查看
阅读
查看源代码
查看历史
更多
搜索
导航
首页
最近更改
随机页面
批量上传文件
WinStory 门户
深色模式
工具
链入页面
相关更改
特殊页面
页面信息
获取短URL