Template:Regex/doc

From Terraria Mods Wiki
Jump to navigation Jump to search

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