๐Ÿ“– Regex Cheatsheet

SyntaxDescriptionExample
.Any character except a newlinea.c โ†’ abc
*0 or more of the preceding elementab* โ†’ a, ab, abb
+1 or more of the preceding elementab+ โ†’ ab, abb
?0 or 1 of the preceding elementcolou?r โ†’ color, colour
{n}Exactly n repetitions of the preceding elementa{3} โ†’ aaa
{n,}n or more repetitions of the preceding elementa{2,} โ†’ aa, aaa
{n,m}Between n and m repetitions of the preceding elementa{2,4} โ†’ aa to aaaa
[abc]Any one of a, b, or c[abc] โ†’ a, b, c
[^abc]Any character except a, b, or c[^abc] โ†’ d, e, ...
[a-z]Any character in the range a to z[a-z] โ†’ a to z
(abc)Groups and captures a subpattern(ab)+ โ†’ ab, abab
(?:abc)Groups without capturing(?:ab)+
(?<name>abc)Named capture group(?<year>\d{4})
|OR โ€” matches either sidecat|dog โ†’ cat, dog
^Start of string (or line)^abc โ†’ abc at the start
$End of string (or line)abc$ โ†’ abc at the end
\dA digit character (same as [0-9])\d+ โ†’ 123
\DA non-digit character\D+ โ†’ abc
\wA word character (letters, digits, underscore)\w+ โ†’ abc_123
\WA non-word character\W โ†’ spaces, symbols
\sA whitespace character (space, tab, newline, etc.)\s+ โ†’ runs of whitespace
\SA non-whitespace character\S+ โ†’ runs of non-whitespace
\bA word boundary\bcat\b โ†’ matches cat only
\BA non-word-boundary position\Bcat โ†’ matches part of concat
(?=abc)Positive lookahead (position followed by abc)\d(?=px) โ†’ the 10 in 10px
(?!abc)Negative lookahead (position not followed by abc)\d(?!px)
(?<=abc)Positive lookbehind (position preceded by abc)(?<=\$)\d+ โ†’ the 100 in $100
(?<!abc)Negative lookbehind (position not preceded by abc)(?<!\$)\d+
*?Non-greedy (shortest) repetition<.*?> โ†’ shortest tag match
\1Backreference to the first capture group(a)\1 โ†’ aa
/iCase-insensitive flag/abc/i โ†’ ABC, abc
/gGlobal flag โ€” finds all matches in the string/a/g
/mMultiline flag (^ and $ match each line)/^a/m

A quick reference chart of commonly used regular expression syntax and symbols, with search-based filtering. Handy for jogging your memory while writing a regex, or as a reference while reading a pattern someone else wrote.

How to use

  1. Type a keyword (e.g. digit, lookahead, capture) into the search box to filter the list.
  2. Check the "Syntax" column for how to write it and the "Description" column for what it means.
  3. Check the "Example" column for a sample regex pattern.

FAQ

Which programming language's regex syntax is this based on?

It's based on JavaScript (ECMAScript) regex syntax, but focuses on fundamental syntax shared across most major languages (Python, PHP, Java, etc.).

Can I actually test a regex pattern here?

This page is reference-only. Use the Regex Tester tool if you want to actually test a pattern.

Does this cover advanced features like named capture groups?

Yes, in addition to basic character classes and quantifiers, it covers advanced syntax like lookahead/lookbehind and named capture groups.