JavaScript RegExps Flashcards
$
Matches end of input
/end$/ matches “This is the end”
Matches beginning of input
/^This/ matches “This is…”
*
Matches zero or more times
/se*/ matches “seeee” as well as “se”
?
Matches zero or one time
/ap?/ matches “apple” and “and”
+
Matches one or more times
/ap+/ matches “apple” but not “and”
{n}
Matches exactly n times
/ap{2}/ matches “apple” but not “apie”
{n,}
Matches n or more times
/ap{2,}/ matches all p’s in “apple” and “apppple” but not “apie”
{n,m}
Matches at least n times, at most m times.
/ap{2,4}/ matches four p’s in
“apppppple”
.
Any character except newline
/a.e/ matches “ape” and “axe”
[…]
Any character within brackets
/a[px]e/ matches “ape” and “axe” but not “ale”
[^…]
Any character but those within brackets
/a[^px]/ matches “ale” but not “ape” or “axe”
\b
Matches on word boundary
/\bno/ matches the first “no” in “nono”
\B
Matches on non word boundary
/\Bno/ matches the second “no” in “nono”
\d
Digits from 0 to 9
/\d{3}/ matches 123 in “Now in 123”
\D
Any non digit character
/\D{2,4}/ matches “Now” in “Now in 123”