This tester uses PHP regular expression (PCRE) functions as a base for its operations. Learn PHP regular expression (PCRE)
Help: Intro, | Pattern Modifiers | Pattern Syntax; | Regular Expression Syntax | Regular Expression Pocket Reference | Mastering Regular Expressions. | Any character |
^ | Start of subject (or line in multiline mode) |
$ | End of subject (or line in multiline mode) |
[ | Start character class definition |
] | End character class definition |
| | Alternates (OR) |
( | Start subpattern |
) | End subpattern |
\ | Escape character |
\n | Newline (hex 0A) |
\r | Carriage return (hex 0D) |
\t | Tab (hex 09) |
\d | Decimal digit |
\D | Charchater that is not a decimal digit |
\h | Horizontal whitespace character |
\H | Character that is not a horizontal whitespace character |
\s | Whitespace character |
\S | Character that is not a whitespace character |
\v | Vertical whitespace character |
\V | Character that is not a vertical whitespace character |
\w | "Word" character |
\W | "Non-word" character |
\b | Word boundary |
\B | Not a word boundary |
\A | Start of subject (independent of multiline mode) |
\Z | End of subject or newline at end (independent of multiline mode) |
\z | End of subject (independent of multiline mode) |
\G | First matching position in subject |
n* | Zero or more of n |
n+ | One or more of n |
n? | Zero or one occurrences of n |
{n} | n occurrences |
{n,} | At least n occurrences |
{,m} | At the most m occurrences |
{n,m} | Between n and m occurrences |
i | (PCRE_CASELESS) If this modifier is set, letters in the pattern match both upper and lower case letters. |
m | (PCRE_MULTILINE) When this modifier is set, the "start of line" and "end of line" constructs match immediately following or immediately before any newline in the subject string, respectively, as well as at the very start and end. |
s | (PCRE_DOTALL) If this modifier is set, a dot metacharacter in the pattern matches all characters, including newlines. |
x | (PCRE_EXTENDED) If this modifier is set, whitespace data characters in the pattern are totally ignored except when escaped or inside a character class, and characters between an unescaped # outside a character class and the next newline character, inclusive, are also ignored. |
A | (PCRE_ANCHORED) If this modifier is set, the pattern is forced to be "anchored", that is, it is constrained to match only at the start of the string which is being searched (the "subject string"). |
D | (PCRE_DOLLAR_ENDONLY) If this modifier is set, a dollar metacharacter in the pattern matches only at the end of the subject string. |
S | If this modifier is set, then this extra analysis is performed. At present, studying a pattern is useful only for non-anchored patterns that do not have a single fixed starting character. |
U | (PCRE_UNGREEDY) This modifier inverts the "greediness" of the quantifiers so that they are not greedy by default, but become greedy if followed by "?". |
X | (PCRE_EXTRA) This modifier turns on additional functionality of PCRE that is incompatible with Perl. Any backslash in a pattern that is followed by a letter that has no special meaning causes an error, thus reserving these combinations for future expansion. |
u | (PCRE_UTF8) This modifier turns on additional functionality of PCRE that is incompatible with Perl. Pattern and subject strings are treated as UTF-8. |
The string or an array with strings to replace. If this parameter is a string and the pattern parameter is an array, all patterns will be replaced by that string. If both pattern and replacement parameters are arrays, each pattern will be replaced by the replacement counterpart. If there are fewer elements in the replacement array than in the pattern array, any extra patterns will be replaced by an empty string.
replacement may contain references of the form \\n or (since PHP 4.0.4) $n, with the latter form being the preferred one. Every such reference will be replaced by the text captured by the n'th parenthesized pattern. n can be from 0 to 99, and \\0 or $0 refers to the text matched by the whole pattern. Opening parentheses are counted from left to right (starting from 1) to obtain the number of the capturing subpattern. To use backslash in replacement, it must be doubled ("\\\\" PHP string).
When working with a replacement pattern where a backreference is immediately followed by another number (i.e.: placing a literal number immediately after a matched pattern), you cannot use the familiar \\1 notation for your backreference. \\11, for example, would confuse preg_replace() since it does not know whether you want the \\1 backreference followed by a literal 1, or the \\11 backreference followed by nothing. In this case the solution is to use \${1}1. This creates an isolated $1 backreference, leaving the 1 as a literal.
When using the deprecated e modifier, this function escapes some characters (namely ', ", \ and NULL) in the strings that replace the backreferences. This is done to ensure that no syntax errors arise from backreference usage with either single or double quotes (e.g. 'strlen(\'$1\')+strlen("$2")'). Make sure you are aware of PHP's string syntax to know exactly how the interpreted string will look.