モジュール:StringReplaceのソースを表示
←
モジュール: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
モジュール:StringReplace
に戻る。
ナビゲーション メニュー
個人用ツール
ログイン
名前空間
モジュール
議論
English
表示
閲覧
履歴表示
その他
検索
案内
索引
脳科学辞典について
最近完成した項目
編集履歴
執筆にあたって
引用の仕方
著作権について
免責事項
問い合わせ
各学会編集のオンライン用語辞典
About us (in English)
Twitter (BrainScienceBot)
ツール
リンク元
関連ページの更新状況
特別ページ
ページ情報
他のプロジェクト