Jump to content

Extension:RegexFunctions/ko

From mediawiki.org
This page is a translated version of the page Extension:RegexFunctions and the translation is 2% complete.
미디어위키 확장 기능 설명서
RegexFunctions
출시 상태: 안정
구현 파서 함수
설명 Regular expression based parser functions
만든 이 Ryan Schmidt (Skizzerz토론)
최신 버전 2.0.0 (2020-03-18)
MediaWiki 1.31+
Licence Public domain
다운로드
Usage
RegexFunctions 확장 기능 번역 (translatewiki.net에서 가능한 경우)

The RegexFunctions extension provides regular expression based parser functions.

Usage

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

#rmatch:
{{#rmatch:string|pattern|then|else}}
string (required) - The text the function uses for the matching.
pattern (required) - The regular expression to use on the text.
then (optional) - What to return if the match was successful. $# and \# contain the captured text. Use ${#}# if you want a group followed by another number.
else (optional) - What to return if the match was not successful. Defaults to an empty string.
#rsplit:
{{#rsplit:string|pattern|piece}}
string (required) - The text the function will split.
pattern (required) - The regular expression to use on the text. No text is captured.
piece (optional) - The piece to return. Defaults to 0 (the first piece). Negative numbers return pieces starting from the end. For example, -1 is the last piece.
#rreplace:
{{#rreplace:string|pattern|replacement}}
string (required) - The text the function will replace.
pattern (required) - The regular expression to use on the text.
replacement (required) - The text to replace the matched text with. $# and \# contain the captured text. Use ${#}# if you want a group followed by another number.

Except for the string parameter, every parameter can be specified either by name or position. For example, {{#rmatch:some string|pattern=^.+$|then=success|else=failure}}. If your wiki's content language is not English, both the English names as well as a translated name may be usable. In addition, every function supports the following named parameters which allow you to modify the behavior of the regex:

  • multiline - If non-empty, ^ and $ match the start and end of each line, rather than the start and end of the entire string.
  • caseless - If non-empty, the pattern is case-insensitive.
  • ungreedy - If non-empty, * and + do not match greedily whereas *? and +? match greedily.
  • extended - If non-empty, the regex can contain spaces and inline comments. See the PHP documentation in the pattern help section for more information.
  • dotall - If non-empty, . matches all characters, including newlines. Normally it does not match newlines.

For example, {{#rmatch:XxXxX|x+|$0|caseless=1}} would result in the output XxXxX because x+ matches both uppercase and lowercase X's when the caseless modifier is set.

Pattern help

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

Delimiters are not required on the pattern in general and should be omitted for readability where possible, but are required if you would like to specify the single-letter modifiers after the pattern. In this event, the delimiters must be forward slashes (no other delimiter type is supported).

Examples

  • {{#rmatch:foo/bar|^foo/|starts with foo/|does not start with foo/}}starts with foo/
  • {{#rsplit:foo/bar/baz|/|-1}}baz
  • {{#rreplace:foo/bar|^(foo)/(bar)$|$2/$1}}bar/foo

설치

  • 파일을 다운로드하고 RegexFunctions 폴더를 extensions/ 디렉토리에 넣어 주세요.
    개발자와 코딩 기여자는 Git을 이용해 확장기능을 다운받는 것이 좋습니다.
    cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/RegexFunctions
    
  • 아래의 코드를 LocalSettings.php 코드의 마지막에 추가합니다.
    wfLoadExtension( 'RegexFunctions' );
    
  • Yes 완료 – 위키의 ‘Special:Version’에 이동해서, 확장기능이 올바르게 설치된 것을 확인합니다.

See also

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