查看“︁Module:StringReplace”︁的源代码
←
Module:StringReplace
跳转到导航
跳转到搜索
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
-- Module for different search and replace operations on strings. local p = {} -- Takes one string parameter, and returns the string with all characters with special meaning for Lua patterns escaped with a preceding `%`. function p.escape_pattern(text) -- Replaces each occurrence of any of ().%+-*?[^$ with a `%` and then the character. local r = string.gsub(text, "[%(%)%.%%%+%-%*%?%[%^%$]", "%%%1") return r end -- Returns the first parameter, with all occurrences of the second parameter replaced with the third parameter. -- All special characters are ignored: {{#invoke:StringReplace|replace_all|test.a%1$foo|%1|bar}} results in `test.abarfoo`. function p.replace_all(frame) local str = frame.args[1] local strToFind = frame.args[2] local strToreplaceWith = frame.args[3] local r = string.gsub(str, p.escape_pattern(strToFind), p.escape_pattern(strToreplaceWith)) return r end p['encode wiki page name'] = function( frame ) local x = mw.ustring.gsub( frame.args[1] or '', '[\'"&_]', { ["'"] = ''', ['"'] = '"', ['&'] = '&', ['_'] = ' ', } ) return mw.text.trim( x ) end return p
该页面使用的模板:
Module:StringReplace/doc
(
查看源代码
)
返回
Module:StringReplace
。
导航菜单
个人工具
中文
创建账号
登录
命名空间
模块
讨论
English
查看
阅读
查看源代码
查看历史
更多
搜索
导航
首页
最近更改
随机页面
MediaWiki帮助
工具
链入页面
相关更改
特殊页面
页面信息