Extension:RegexFunctions

From MediaWiki.org
Jump to navigation Jump to search
This page is a translated version of the page Extension:RegexFunctions and the translation is 31% complete.

Other languages:
English • ‎dansk • ‎日本語
MediaWiki 拡張機能マニュアル
OOjs UI icon advanced.svg
RegexFunctions
リリースの状態: ベータ
実装 パーサー関数
説明 Regular expression based parser functions
作者 Ryan Schmidt (Skizzerztalk)
最新バージョン 1.5.0 (2017-10-30)
MediaWiki 1.23+
ライセンス パブリック ドメイン
ダウンロード
使用法
更新履歴
  • $wgRegexFunctionsPerPage
  • $wgRegexFunctionsAllowModifiers
  • $wgRegexFunctionsAllowE
  • $wgRegexFunctionsAllowOptions
  • $wgRegexFunctionsLimit
  • $wgRegexFunctionsDisable
translatewiki.net で翻訳を利用できる場合は、RegexFunctions 拡張機能の翻訳にご協力ください
使用状況とバージョン マトリクスを確認してください。

The RegexFunctions extension provides regular expression based parser functions.

使用法

As of now, this extension defines three parser functions, rmatch, rsplit, and rreplace

#rmatch:
{{#rmatch:string|pattern|return|notfound|offset}}
string (必須): The text the function uses for the matching.
pattern (必須): The regular expression to use on the text.
return (必須): What to return if the match was successful. $# and \# contain the captured text, and $$# and \\# contain the offsets of that text. Use ${#}# or \{#}# if you want a group followed by another number.
notfound (省略可能): What to return if the match was not successful. Defaults to an empty string.
offset (省略可能): The offset in bytes to start the match at. Defaults to 0 (the beginning of the text).
#rsplit:
{{#rsplit:string|pattern|piece}}
string (必須): The text the function will split.
pattern (必須): The regular expression to use on the text. No text is captured.
piece (省略可能): The piece to return. Defaults to 0 (the first piece).
#rreplace:
{{#rreplace:string|pattern|replace}}
string (必須): The text the function will replace.
pattern (必須): The regular expression to use on the text.
replace (必須): The text to replace the matched text with. Both $# and \# will call the capturing groups, use ${#}# or \{#}# if you want a group followed by another number.

パターン ヘルプ

For help on constructing the syntax, please read [1] for general help and [2] for an overview of the modifiers.

インストール

  • ダウンロードして、ファイルを extensions/ フォルダー内の RegexFunctions という名前のディレクトリ内に配置します。
  • 以下のコードを LocalSettings.php の末尾に追加します:
    require_once "$IP/extensions/RegexFunctions/RegexFunctions.php";
    
  • Configure as required
  • Yes 完了 – ウィキの「Special:Version」に移動して、拡張機能が正しくインストールされたことを確認します。

Configuration

$wgRegexFunctionsPerPage
How many functions are allowed per page. Default is 10, but it is recommended that it is set above 3 for usability.
$wgRegexFunctionsAllowModifiers
Allows modifiers (e.g./i for case insensitivity). Does not enable the /e modifier in the rreplace function, see the next variable for that. Defaults to true.
$wgRegexFunctionsAllowModifiers
Allows modifiers (e.g./i for case insensitivity). Does not enable the /e modifier in the rreplace function, see the next variable for that. Defaults to true.
$wgRegexFunctionsAllowE
Allows the /e modifier in rreplace, which treats the 'replace' text as PHP code. Don't enable this unless you trust all of your users, as it opens up XSS vectors and other security concerns. Defaults to false.
$wgRegexFunctionsAllowOptions
Allows internal options (e.g. (?U) for ungreedy) inside of the regex itself. Defaults to true.
$wgRegexFunctionsLimit
Limit for the number of pieces in the rsplit function and replaces in the rreplace function. -1 is unlimited. Defaults to -1.
$wgRegexFunctionsDisable
Array of functions you want to disable. Defaults to an empty array.

更新履歴

Version 1.5.0
Removed backwards compatible I18n shim.
Version 1.4.3
Fixed critical security issue (patch by User:Pastakhov).
Version 1.4.2
Fixed issue in PHP 5.3 about pass-by-reference stuff in the rreplace function.
Version 1.4.1
Fixed issue where disabling rmatch disabled every function, and it was otherwise impossible to disable rsplit and rreplace.
Version 1.4.0
Moved to new message declaration style, nothing changed frontend-wise
Version 1.3.0
Sanitation process should no longer misinterpret things as internal options.
Version 1.2.0
Pattern goes through a sanitation process before being passed onto one of the preg_* functions.
Version 1.1.0
Localization updates
Version 1.0.0
Initial Release, defines three functions: rmatch, rsplit, and rreplace

関連項目

  • ReplaceSet - an excellent substitute for using nested #replace commands when you need to perform a sequence of replaces on a single text string.
  • StringFunctions - some helpful string operations.
  • Regex Fun - just another regex extension with more functionality but without any customization variables for limitations.