/ mozey.co / blog

regex

April 13, 2016

🔗 Javascript

🔗 Regex editor

scriptular is on github

🔗 Cheatsheet

Modifiers:

i	Perform case-insensitive matching
g	Perform a global match

Brackets:

[abc]	    Match a single character a, b, or c
[^abc]	    Match any character except a, b, or c
[A-z]	    Match any character from uppercase A to lowercase z
(ab|cd|ef)	Match either ab, cd, or ef
(...)	    Capture anything enclosed

Metacharacters

^	    Start of line
$	    End of line
.	    Match any character
\w	    Match a word character
\W	    Match a non-word character
\d	    Match a digit
\D	    Match any non-digit character
\s	    Match a whitespace character
\S	    Match a non-whitespace character
\b	    Match character at the beginning or end of a word
\B	    Match a character not at beginning or end of a word
\0	    Match a NUL character
\t	    Match a tab character
\xxx	Match a character specified by octal number xxx
\xdd	Match a character specified by hexidecimal number dd
\uxxxx	Match a Unicode character specified by hexidecimal number xxxx

Quantifiers

n+	    Match at least one n
n*	    Match zero or more n's
n?	    Match zero or one n
n{X}	Match sequence of X n's
n{X,Y}	Match sequence of X to Y n's
n{X,}	Match sequence of X or more n's