AI Generate Regex docs instantly

Regex Cheat Sheet

Quick reference guide with copy-paste ready code snippets

Try DocuWriter Free

Basic Patterns

4 snippets

Fundamental regex syntax

Literal Match

hello     # Matches "hello"

Any Character

.         # Any single character
h.t       # hat, hit, hot, h@t

Escape Special

\.        # Literal dot
\$        # Literal dollar sign
\(\)      # Literal parentheses

Anchors

^start    # Start of line
end$      # End of line
^exact$   # Exact match
\bword\b  # Word boundary

Character Classes

3 snippets

Match sets of characters

Brackets

[abc]     # a, b, or c
[^abc]    # NOT a, b, or c
[a-z]     # Any lowercase letter
[A-Za-z]  # Any letter
[0-9]     # Any digit

Shorthand

\d        # Digit [0-9]
\D        # Non-digit
\w        # Word char [A-Za-z0-9_]
\W        # Non-word char
\s        # Whitespace
\S        # Non-whitespace

POSIX Classes

[:alpha:] # Letters
[:digit:] # Digits
[:alnum:] # Alphanumeric
[:space:] # Whitespace

Quantifiers

3 snippets

Specify repetition

Basic

a*        # 0 or more
a+        # 1 or more
a?        # 0 or 1
a{3}      # Exactly 3
a{2,4}    # 2 to 4
a{2,}     # 2 or more

Greedy vs Lazy

.*        # Greedy (match most)
.*?       # Lazy (match least)
.+?       # Lazy 1 or more
.{2,4}?   # Lazy range

Examples

\d+       # One or more digits
\w{3,8}   # 3-8 word characters
https?    # http or https

Tired of looking up syntax?

DocuWriter.ai generates documentation and explains code using AI.

Try Free

Groups & Alternation

5 snippets

Group patterns and alternatives

Capturing Group

(abc)     # Capture "abc"
(\d{3})-(\d{4})  # Phone parts

Non-capturing

(?:abc)   # Group without capture

Alternation

cat|dog   # cat OR dog
(jpg|png|gif)  # Image extensions

Backreference

(\w+) \1  # Repeated word
(['"]).*?\1  # Matching quotes

Named Groups

(?<name>\w+)  # Named capture
\k<name>      # Named backreference

Lookahead & Lookbehind

4 snippets

Assert without consuming

Positive Lookahead

foo(?=bar)    # foo followed by bar
\d+(?=px)     # Digits before "px"

Negative Lookahead

foo(?!bar)    # foo NOT followed by bar
\d+(?!px)     # Digits not before "px"

Positive Lookbehind

(?<=\$)\d+   # Digits after "$"
(?<=@)\w+    # Word after "@"

Negative Lookbehind

(?<!\$)\d+   # Digits not after "$"

Common Patterns

7 snippets

Frequently used expressions

Email

[\w.-]+@[\w.-]+\.\w+

URL

https?://[\w.-]+(/[\w./-]*)?

Phone (US)

\(?\d{3}\)?[-. ]?\d{3}[-. ]?\d{4}

Date (YYYY-MM-DD)

\d{4}-\d{2}-\d{2}

IPv4 Address

\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}

Hex Color

#[0-9A-Fa-f]{6}\b

Username

^[a-zA-Z][a-zA-Z0-9_]{2,15}$

Flags & Modifiers

5 snippets

Change regex behavior

Case Insensitive

/pattern/i    # JavaScript
(?i)pattern   # Inline flag

Global

/pattern/g    # Match all

Multiline

/pattern/m    # ^ and $ match line breaks

Dotall

/pattern/s    # . matches newlines

Combined

/pattern/gim  # Multiple flags

More Cheat Sheets

FAQ

Frequently asked questions

What is a Regex cheat sheet?

A Regex cheat sheet is a quick reference guide containing the most commonly used syntax, functions, and patterns in Regex. It helps developers quickly look up syntax without searching through documentation.

How do I learn Regex quickly?

Start with the basics: variables, control flow, and functions. Use this cheat sheet as a reference while practicing. For faster learning, try DocuWriter.ai to automatically explain code and generate documentation as you learn.

What are the most important Regex concepts?

Key Regex concepts include variables and data types, control flow (if/else, loops), functions, error handling, and working with data structures like arrays and objects/dictionaries.

How can I document my Regex code?

Use inline comments for complex logic, docstrings for functions and classes, and README files for projects. DocuWriter.ai can automatically generate professional documentation from your Regex code using AI.

Code Conversion Tools

Convert Regex to Other Languages

Easily translate your Regex code to other programming languages with our AI-powered converters

Related resources

Stop memorizing. Start shipping.

Generate Regex Docs with AI

DocuWriter.ai automatically generates comments, docstrings, and README files for your code.

Auto-generate comments
Create README files
Explain complex code
API documentation
Start Free - No Credit Card

Join 33,700+ developers saving hours every week