Toolkitly
One moment…
toolkitly

Regex Cheat Sheet

Regex pattern reference.

45/45
//Characters10

Any character

Any single character except newline

$.

Digit

Matches a digit (0-9)

$\d

Non-digit

Matches anything that is not a digit

$\D

Word character

Matches [A-Za-z0-9_]

$\w

Non-word character

Matches anything not [A-Za-z0-9_]

$\W

Whitespace

Space, tab, newline, carriage return

$\s

Non-whitespace

Any non-whitespace character

$\S

Character class

Matches any listed character

$[aeiou]

Negated class

Matches anything not listed

$[^aeiou]

Range

Lowercase letters

$[a-z]
//Quantifiers7

Zero or more

Greedy match 0 or more times

$*

One or more

Greedy match 1 or more times

$+

Zero or one

Optional match (0 or 1)

$?

Exactly n

Exactly n times

${n}

n or more

At least n times

${n,}

Between n and m

At least n and at most m times

${n,m}

Lazy match

Non-greedy version of *

$*?
//Anchors5

Start of string

Matches start of input

$^

End of string

Matches end of input

$$

Word boundary

Position between word and non-word character

$\b

Non-word boundary

Not a word boundary

$\B

Start of line (multiline)

Start of line when /m flag is set

$^
//Groups5

Capturing group

Groups and captures matched text

$(abc)

Non-capturing group

Groups without capturing

$(?:abc)

Named group

Group with a name reference

$(?<name>abc)

OR alternation

Match either side of |

$cat|dog

Backreference

Find repeated word using \1

$\b(\w+)\s+\1\b
//Lookarounds4

Positive lookahead

Match foo only if followed by bar

$foo(?=bar)

Negative lookahead

Match foo only if NOT followed by bar

$foo(?!bar)

Positive lookbehind

Match bar only if preceded by foo

$(?<=foo)bar

Negative lookbehind

Match bar only if NOT preceded by foo

$(?<!foo)bar
//Flags6

Global (g)

Find all matches, not just the first

$/pattern/g

Case insensitive (i)

Ignore case

$/pattern/i

Multiline (m)

^ and $ match start/end of each line

$/pattern/m

Dot all (s)

. matches newlines too

$/pattern/s

Unicode (u)

Treat pattern as Unicode

$/pattern/u

Sticky (y)

Match from lastIndex only

$/pattern/y
//Patterns8

Email

Basic email validation

$^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$

URL

HTTP or HTTPS URL

$https?://[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#[\]@!$&'()*+,;=]+

IPv4

Valid IPv4 address

$\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b

US phone

(555) 123-4567 or 555-123-4567

$^\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$

ISO date

YYYY-MM-DD

$^\d{4}-\d{2}-\d{2}$

Hex color

#fff or #ffffff

$^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$

Strong password

8+ chars, 1 upper, 1 lower, 1 digit

$^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$

Username

3-16 alphanumeric or underscore

$^[a-zA-Z0-9_]{3,16}$