Regular Expression Tester

RegExp Tester

Enter Your Regular Expression:

Enter Your Sample Text:

PCRE Cheat Sheet

Meta Characters
^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 ( a|b matches a or b )
(Start subpattern
)End subpattern
\Escape character
Pattern Modifiers
iIgnore case
mMultiline mode
sDotall ( . includes newline )
xExtended - comments & whitespace
eEnables evaluation of replacement as PHP code
SExtra analysis of pattern
UPattern is ungreedy
uPattern is treated as UTF-8
Base Character Classes
\wAny "word" character (a-z 0-9 _)
\WAny non-"word" character
\sWhitespace (space, tab, CRLF)
\SAny non-whitespace character
\dDigits (0-9)
\DAny non-digit character
.Any character except newline
n*Zero or more of n
n+One or more of n
n?Zero or one occurrence of n
{n}n occurrences exactly
{n,}At least n occurrences
{,m}At most m occurrences
{n,m}Between n and m occurrences inclusive
Point Based Assertions
\bWord boundary
\BNot a word boundary
\AStart of a subject
\ZEnd of a Subject or newline at end
\zEnd of a Subject
\GFirst matching position in subject
Subpatern Modifiers & Assertions
(?:)Non capturing subpattern((?:foo|fu)bar) matches foobar or fubar without foo or fu appearing as a captured subpattern
(?=)Positive look ahead assertionfoo(?=bar) matches foo when followed by bar
(?!)Negative look ahead assertionfoo(?!bar) matches foo when not followed by bar
(?<=)Positive look behind assertion(?<=foo)bar matches bar when preceded by foo
(?<!)Negative look behind assertion(?<!foo)bar matches bar when not preceded by foo
(?>)Once-only subpatterns(?>\d+)bar Performance enhancing when bar not present
(?(x))Conditional subpatterns(?(3)foo|fu)bar Matches foo if 3rd subpattern has matched, fu if not
(?#)Comment(?# Pattern does x y or z)