Boneyard Tools

Regular Expression Cheatsheet

A searchable cheatsheet for regular expressions. Browse by group or search by token or meaning to find anchors, character classes, quantifiers, groups, lookarounds and flags, each with a short example.

How to use the regex cheatsheet

  1. Search for a token like \d or a word like digit or anchor.
  2. Read the meaning and the short example for each match.
  3. Copy the token straight into your pattern.

Examples

Match any digit

\d
Any digit, equivalent to [0-9]

Positive lookahead

(?=...)
Assert what follows without consuming it

Frequently asked questions

What does \d mean in regex?

\d matches any single digit and is equivalent to the character class [0-9]. Its opposite, \D, matches any non-digit.

What is the difference between * and +?

The star matches zero or more of the preceding token, so it can match nothing. The plus matches one or more, so it requires at least one occurrence.

What is a lookahead?

A lookahead like (?=...) asserts that some pattern follows the current position without including it in the match. (?!...) asserts that a pattern does not follow.

What do regex flags like g, i and m do?

The g flag finds all matches, i makes matching case-insensitive, and m lets the anchors ^ and $ match at line breaks rather than only the whole string.

How do I match a literal special character?

Escape it with a backslash. For example, \. matches a literal dot and \\ matches a literal backslash.

Related tools