Regex Cheatsheet

Quick reference for regular expression syntax

Open Regex Tester →

Anchors

^Start of string (or line with m flag)
$End of string (or line with m flag)
\bWord boundary
\BNon-word boundary
\AStart of string (no multiline)
\ZEnd of string (no multiline)

Character Classes

[abc]Any of a, b, or c
[^abc]Not a, b, or c
[a-z]Lowercase a through z
[A-Z]Uppercase A through Z
[0-9]Digit 0 through 9
[a-zA-Z]Any letter
.Any character except newline
\wWord char [a-zA-Z0-9_]
\WNon-word character
\dDigit [0-9]
\DNon-digit
\sWhitespace (space, tab, newline)
\SNon-whitespace

Quantifiers

*0 or more (greedy)
+1 or more (greedy)
?0 or 1 (optional)
{n}Exactly n times
{n,}n or more times
{n,m}Between n and m times
*?0 or more (lazy)
+?1 or more (lazy)
??0 or 1 (lazy)

Flags

gGlobal — find all matches
iCase-insensitive
mMultiline — ^ and $ match line boundaries
sDotall — . matches newlines
uUnicode support
ySticky — match at lastIndex only

Groups & Lookarounds

(abc)Capturing group
(?:abc)Non-capturing group
(?<name>abc)Named capturing group
(?=abc)Positive lookahead
(?!abc)Negative lookahead
(?<=abc)Positive lookbehind
(?<!abc)Negative lookbehind
\1Back-reference to group 1
\k<name>Back-reference to named group

Escape Sequences

\nNewline
\tTab
\rCarriage return
\0Null character
\uXXXXUnicode code point
\\Literal backslash
\.Literal dot

Common Patterns

^\d+$Integer (digits only)
^\d*\.?\d+$Decimal number
^-?\d+$Integer (optional negative)
^\w+$Alphanumeric + underscore only
^[a-zA-Z]+$Letters only
^\s*$Empty or whitespace only
\S+One or more non-whitespace

Useful Recipes

^[\w.+-]+@[\w-]+\.[a-zA-Z]{2,}$Email (simplified)
^\d{4}-\d{2}-\d{2}$Date YYYY-MM-DD
^#[0-9a-fA-F]{3,6}$Hex color
^https?:\/\/URL starting with http(s)
^\+?[\d\s\-()]{7,}$Phone number (loose)
^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$UUID v4
^(?=.*[A-Z])(?=.*\d).{8,}$Password (min 8, uppercase, digit)

Want a deeper explanation? Read the Regex Guide or jump straight to the Regex Tester.

Online Regular Expression Tester

io9.me Regex Tester lets you write and test JavaScript regular expressions with instant visual feedback. Type a pattern and test string, and matches are highlighted in real time. Capture groups are extracted and displayed alongside each match.

Features

  • Live matching — see results instantly as you type the pattern or test string
  • Capture groups — view numbered and named groups for every match
  • All JavaScript flags — global (g), case-insensitive (i), multiline (m), dotAll (s), unicode (u), sticky (y)
  • Color-coded match highlighting in the test string
  • Quick-reference cheatsheet for regex syntax
  • Replace mode to test substitution patterns

How to use

  1. Enter a regex pattern in the pattern field.
  2. Toggle flags (g, i, m, etc.) as needed.
  3. Paste or type your test string below.
  4. Matches are highlighted in real time; capture groups appear in the results panel.

Common regex patterns

  • Email validation: [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}
  • URL matching: https?:\/\/[^\s]+
  • IP address: \b\d{1,3}(\.\d{1,3}){3}\b
  • Date (YYYY-MM-DD): \d{4}-\d{2}-\d{2}

Related tools and guides