Regex
Wednesday, August 8, 2018
8:11 AM
Assertions/Quantifiers
$
matches end of line
^
matches beginning of line
0 or more
?
0 or more
{n}
exactly n
(n,}
n or more
{n,m}
between n and m
[link]
Characters
.
any except newline
[abc]
a,b or c
[a-z]
a,b, …,z
[^abc]
anything but a,b,c
\d
digit
\s
space
\w
word character
Special
\n
newline
\t
tab
\d
\d 
enables digits from other languages to qualify
\w
enables word letters from other languages to qualify
Syntax
()
parantheses
|
pipe
[]
square bracket
{}
quantifier
Ranges
0-9
one (one 1!) of these from the range o-9 or either 0,1,2,3,4,5,6,7,8 or 9)
Quantifiers
{n}
(one number from the given range, n times) match exactly
{n,}
match that number or more
{n,n}
match either x, y numbers
^[0-9]{5}$
5 times a number from the given range
^[0-9]+$
more than one number from the given range
[link]
Inverter
^
used to indicate matches first char
^
used to invert or opposite of 
^[^0-9]+$
none of numbers are ok
JavaScript regex quick reference (hide): 
[abx-z]
One character of: a, b, or the range x-z
[^abx-z]
One character except: a, b, or the range x-z
a|b
a or b
a?
Zero or one a's (greedy)
a??
Zero or one a's (lazy)
a*
Zero or more a's (greedy)
a*?
Zero or more a's (lazy)
a+
One or more a's (greedy)
a+?
One or more a's (lazy)
a{4}
Exactly 4 a's
a{4,8}
Between (inclusive) 4 and 8 a's
a{9,}
9 or more a's
(?=...)
A positive lookahead
(?!...)
A negative lookahead
(?:...)
A non-capturing group
(...)
A capturing group
^
Beginning of the string
$
End of the string
\d
A digit (same as [0-9])
\D
A non-digit (same as [^0-9])
\w
A word character (same as [_a-zA-Z0-9])
\W
A non-word character (same as [^_a-zA-Z0-9])
\s
A whitespace character
\S
A non-whitespace character
\b
A word boundary
\B
A non-word boundary
\n
A newline
\t
A tab
\cY
The control character with the hex code Y
\xYY
The character with the hex code YY
\uYYYY
The character with the hex code YYYY
.
Any character
\Y
The Y'th captured group
Phone Number
^[0-9]{3}-?[0-9]{3}-?[0-9]{4}$
613-869-1022
Email
^[a-zA-Z0-9._]+@[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$
luc.trudel@gmail.com
[link]