Template: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