A Live Regular Expression Tester for PHP:
Test PHP regular expressions live in your browser and generate sample code for preg_match, preg_match_all, preg_replace, preg_grep, and preg_split!
PHP Live Regex
Cheat Sheet | |||||
[abc] |
A single character of: a, b or c | . |
Any single character | (...) |
Capture everything enclosed |
[^abc] |
Any single character except: a, b or c | \s |
Any whitespace character | (a|b) |
a or b |
[a-z] |
Any single character in the range a-z | \s |
Any non-whitespace character | a? |
Zero or one of a |
[a-zA-Z] |
Any single character in the range a-z or A-Z | \d |
Any digit | a* |
Zero or more of a |
^ |
Start of line | \D |
Any non-digit | a+ |
One or more of a |
$ |
End of line | \w |
Any word character (letter, number, underscore) | a{3} |
Exactly 3 of a |
\A |
Start of string | \w |
Any non-word character | a{3,} |
3 or more of a |
\z |
End of string | \b |
Any word boundary | a{3,6} |
Between 3 and 6 of a |
Options | |||||
i | case insensitive | ||||
m | treat as multi-line string | ||||
s | dot matches newline | ||||
x | ignore whitespace in regex | ||||
A | matches only at the start of string | ||||
D | matches only at the end of string | ||||
U | non-greedy matching by default |