Template:Regex

From Terraria Wiki
Jump to: navigation, search
Template-info.svg Documentation The documentation below is transcluded from Template:Regex/doc. (edit | history)

Do a regex match or replace.

Usage[edit source]

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

Match[edit source]

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

return yes if matched, return empty string if failed.

Replace[edit source]

{{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[edit source]

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