& L
Basic metacharacters
Metacharacters |
Description |
. |
Match any single character |
| |
Logic or operator |
[] |
Define a character set combination to match one character in the Set |
[^] |
Evaluate the non-union of character sets (the non-union of the entire set, rather than the character next to the ^ symbol) |
- |
Define a range in the character set. For example, [A-Za-Z] |
/ |
Escape the next character. For example,/n indicates line feed. |
Number of metacharacters
Metacharacters |
Description |
* |
Matches the previous character (subexpression) zero or multiple times |
*? |
* Lazy version (to prevent regular expressions from being "greedy ") |
+ |
Match the previous character or subexpression once or multiple times |
+? |
+ Lazy version |
? |
Matches the first character or subexpression zero or once |
{N} |
Match n times of the previous character or subexpression, for example, [A-Z] {6} indicates matching a string consisting of six uppercase letters. |
{M, n}
T;/td> |
Match at least m times and at most n times |
{M ,} |
Match at least m times |
{M ,}? |
{M,} lazy version |
Location metacharacters
Metacharacters |
Description |
^ |
Beginning of Line |
$ |
End of line |
/< |
Start with a word |
/> |
Word end |
/B |
Word boundary (start and end of a word) |
/B |
/B. |
Special metacharacters
Metacharacters |
Description |
[/B] |
Match a space character |
/C |
Match A Control Character |
/D |
Match any number character, equivalent to [0-9] |
/D |
/D. |
/F |
Page feed |
/N |
Line Break |
/R |
Carriage Return |
/S |
Match a blank character |
/S |
/S. |
/T |
Tab |
/V |
Vertical Tab |
/W |
Match any letter, number, or underline. Equivalent to [A-Za-z0-9 _] |
/W |
/W. |
/X |
Matches a hexadecimal number. |
/0 |
Matches an octal number. |
Retrospective reference and search
Metacharacters |
Description |
() |
Define a subexpression |
/1 |
The first subexpression. Similarly,/2 indicates 2nd subexpressions. /0 usually indicates the entire regular expression. |
? = |
Forward lookup |
? <= |
Backward Search |
?! |
Negative forward lookup |
?! = |
Negative backward Lookup |
? () |
Condition (if then) |
? () | |
Condition (if then else) |
In addition,/e,/L,/L,/U, and so on indicate case-insensitive conversion. (? M) indicates that the regular expression is matched using the branch matching mode. All of the above are tested using the preg series functions in PHP. For special metacharacters, there are also POSIX character classes: [: alnum:], [: Alpha:], [: cntrl:], [: digit:], [: graph:], [: blank:], [: lower:], [: Print:], [: punct:], [: Space:], [: Upper:], [: xdigit:]