Login here
or
Sign up free
Home
Validate
Library
Other
javascript :: Match
Regular expression validation
Validation
Hide/Show
Pattern
Match
Pattern Modifiers:
Example
Permalink
Share
Run
Result
Hide/Show
Not checked
Result dump
Hide/Show
Not checked
Social bookmark
Useful? Share this page with others.
Pattern Cheatsheet
Special Sequences
\w
Any "word" character (a-z 0-9 _)
\W
Any non "word" character
\s
Whitespace (space, tab CRLF)
\S
Any non whitepsace character
\d
Digits (0-9)
\D
Any non digit character
.
Any character except newline
Quantifiers
n*
Zero or more of n
n+
One or more of n
n?
Zero or one occurrences 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
\b
Word boundary
\B
Not a word boundary
\A
Start of subject
\Z
End of subject or newline at end
\z
End of subject
\G
First matching position in subject
Pattern Modifiers
i
Case Insensitive
m
Multiline mode - ^ and $ match start and end of lines
s
Dotall - . class includes newline
x
Extended– comments and whitespace
e
preg_replace(PHP) only – enables evaluation of replacement as PHP code
S
Extra analysis of pattern
U
Pattern is ungreedy
u
Pattern is treated as UTF-8
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, eg (a|b) matches a or b
(
Start subpattern
)
End subpattern
\
Escape character
Backslashes
\n
newline
\r
carriage return
\t
tab
\xhh
character with hex code hh
\ddd
character with octal code ddd
Assertions
(?=)
Positive look ahead assertion foo(?=bar) matches foo when followed by bar
(?!)
Negative look ahead assertion foo(?!bar) matches foo when not followed by bar
(?<=)
Positive look behind assertion (?<=foo)bar matches bar when preceded by foo
(?
Negative look behind assertion (?
(?>)
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)