模板:Regex

出自Terraria Wiki
跳至導覽 跳至搜尋
Template-info.svg 文檔 以下文檔來自Template:Regex/doc。(編輯 | 歷史
Warning-red.svg
Deprecated template! Please use RegexFunctions instead.

Do a regex match or replace.

Usage

Note: regex is a regular expression as defined by php preg_replace().

Match

{{regex|[string]|[regex]}}

return yes if matched, return empty string if failed.

Replace

{{regex|[string]|[regex]|[replacement]|[if failed (optional)]}}

Replaces the given pattern within the string by replacement. If no replacement occurs, return unnamed parameter 4 (empty string by default).

Example

Code Result
{{regex|abcde|/^a.+e$/}} yes
{{regex|abcde|/x/}}
{{regex|xx@@xx|/@@/|yy|zzz}} xxyyxx
{{regex|xx@@xx|/@@/|t\0t|zzz}} xxt@@txx
{{regex|xx@@xx|/@@@@/|yy|zzz}} zzz
{{regex|xx@@xx|/@@@@/|yy}}
{{regex|xx@@xx|/@@@@/|yy|xx@@xx}} xx@@xx
{{regex|xx@@xx|/@@/||zzz}} xxxx