Regex Cheat Sheet

Quick reference for regular expression syntax across flavours.

Filter (optional)
Symbol            | Meaning
------------------+--------------------------------------------
^                 | Start of string / line (m flag)
$                 | End of string / line (m flag)
.                 | Any char except newline (s flag = include)
\d \D             | Digit / non-digit
\w \W             | Word char [A-Za-z0-9_] / non-word
\s \S             | Whitespace / non-whitespace
\b \B             | Word boundary / non-boundary
[abc]             | Character class — any of a, b, c
[^abc]            | Negated class — not a, b, c
[a-z]             | Range
a|b               | Alternation
a?                | 0 or 1
a*                | 0 or more (greedy)
a+                | 1 or more (greedy)
a*?               | 0 or more (lazy)
a+?               | 1 or more (lazy)
a{n}              | Exactly n
a{n,}             | n or more
a{n,m}            | Between n and m
(abc)             | Capturing group
(?:abc)           | Non-capturing group
(?<name>abc)      | Named group
\1 \k<name>       | Backreference
(?=abc)           | Positive lookahead
(?!abc)           | Negative lookahead
(?<=abc)          | Positive lookbehind
(?<!abc)          | Negative lookbehind
/.../i            | Case-insensitive flag
/.../g            | Global flag (JS)
/.../m            | Multiline — ^ $ match line bounds
/.../s            | Dotall — . matches newline
/.../u            | Unicode mode
\xHH \uHHHH       | Hex / Unicode escape

About this tool

Quick reference for regular expression syntax across flavours.

An unhandled error has occurred. Reload ×