Regex Cheat Sheet

Interactive regex reference with categories: anchors, quantifiers, groups, character classes, lookahead/lookbehind. Examples for each pattern. Built-in regex tester.

7.5Kuses
8.6/10(331)

Regex Tester

PatternDescriptionExampleMatches
^Start of string (or line with m flag)^Hello"Hello world" -> "Hello"
|
$End of string (or line with m flag)world$"Hello world" -> "world"
|
\bWord boundary\bcat\b"a cat sat" -> "cat"
|
\BNon-word boundary\Bcat\B"concatenate" -> "cat"
|
*Zero or more (greedy)a*"aaa" -> "aaa", "" -> ""
|
+One or more (greedy)a+"aaa" -> "aaa"
|
?Zero or one (optional)colou?r"color" and "colour"
|
{n}Exactly n timesa{3}"aaa" -> "aaa"
|
{n,}n or more timesa{2,}"aa", "aaa", "aaaa"...
|
{n,m}Between n and m timesa{2,4}"aa", "aaa", "aaaa"
|
*?Zero or more (lazy)a*?Matches as few as possible
|
+?One or more (lazy)a+?Matches as few as possible
|
??Zero or one (lazy)a??Prefers zero
|
.Any character except newlinec.t"cat", "cut", "c1t"
|
[abc]Any of a, b, or c[aeiou]Any vowel
|
[^abc]Not a, b, or c[^0-9]Any non-digit
|
[a-z]Any char from a to z[a-zA-Z]Any letter
|
\dAny digit [0-9]\d{3}"123", "456"
|
\DAny non-digit [^0-9]\D+"abc", "hello"
|
\wWord character [a-zA-Z0-9_]\w+"hello", "var_1"
|
\WNon-word character\W+" ", "!@#"
|
\sWhitespace [ \t\n\r\f]\s+" ", "\t", "\n"
|
\SNon-whitespace\S+"hello", "123"
|
(abc)Capturing group(\d{3})-(\d{4})Captures area code and number
|
(?:abc)Non-capturing group(?:ab)+"abab" without capturing
|
(?<name>abc)Named capturing group(?<year>\d{4})Captures with name "year"
|
\1Backreference to group 1(\w+)\s+\1"the the" (repeated word)
|
(a|b)Alternation (or)(cat|dog)"cat" or "dog"
|
(?=abc)Positive lookahead\d+(?= dollars)"100" in "100 dollars"
|
(?!abc)Negative lookahead\d+(?! dollars)"100" NOT followed by " dollars"
|
(?<=abc)Positive lookbehind(?<=\$)\d+"100" in "$100"
|
(?<!abc)Negative lookbehind(?<!\$)\d+"100" NOT preceded by "$"
|
\nNewlineline1\nline2Matches newline character
|
\tTabcol1\tcol2Matches tab character
|
\rCarriage return\r\nWindows line ending
|
\\Literal backslashC:\\Users"C:\Users"
|
\.Literal dotfile\.txt"file.txt"
|
gGlobal - find all matches/cat/gAll occurrences of cat
iCase insensitive/hello/i"Hello", "HELLO", "hello"
mMultiline - ^ and $ match per line/^start/mStart of each line
sDotall - dot matches newline/a.b/s"a\nb" (across lines)
uUnicode support/\u{1F600}/uUnicode emoji matching
EmailEmail address pattern[\w.-]+@[\w.-]+\.\w{2,}"user@example.com"
URLURL patternhttps?://[\w.-]+(?:/[\w.-]*)*"https://example.com/path"
IP AddressIPv4 address\d{1,3}(?:\.\d{1,3}){3}"192.168.1.1"
PhoneUS phone number\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}"(555) 123-4567"
DateDate (YYYY-MM-DD)\d{4}-\d{2}-\d{2}"2024-01-15"
Hex ColorCSS hex color#(?:[0-9a-fA-F]{3}){1,2}"#FFF", "#3B82F6"
HTML TagHTML opening tag<([a-z][a-z0-9]*)\b[^>]*>"<div class=\"x\">"
IntegerSigned integer-?\d+"42", "-7", "0"
DecimalDecimal number-?\d+\.?\d*"3.14", "-2.5", "42"

About Regular Expressions

Regular expressions (regex) are powerful patterns used for string matching, searching, and manipulation. This cheat sheet covers all major regex syntax with examples and a built-in tester.

Features

  • Comprehensive regex reference organized by category
  • Examples and match descriptions for every pattern
  • Built-in regex tester with highlighting
  • Common real-world patterns (email, URL, phone, etc.)
  • Click any pattern to test it instantly
⚡ Pro OptionsSponsored

Some links on this page are affiliate links. If you click and make a purchase, we may earn a commission at no extra cost to you.

Recommended Products

Ad

Affiliate Disclosure: As an Amazon Associate, ToolBird earns from qualifying purchases. Links above are affiliate links — if you buy through them, we may earn a small commission at no extra cost to you.

Disclaimer: This tool is provided as-is for informational and educational purposes only.

ToolBird Assistant

Find the right tool instantly

Hey! I'm ToolBird Assistant. Tell me what you need and I'll find the right tool for you.