Regex Cheat Sheet

Regular expressions syntax reference guide

Regex Cheat Sheet

Quick reference guide for Regular Expressions. Click the copy button to copy any pattern.

81
Total Commands
81
Filtered Results

Character Classes

CommandCopyDescription
.Any character except newline
\dAny digit (0-9)
\DAny non-digit
\wAny word character (a-z, A-Z, 0-9, _)
\WAny non-word character
\sAny whitespace character
\SAny non-whitespace character
[abc]Any character in set (a, b, or c)
[^abc]Any character not in set
[a-z]Any lowercase letter
[A-Z]Any uppercase letter
[0-9]Any digit

Quantifiers

CommandCopyDescription
*Zero or more times
+One or more times
?Zero or one time (optional)
{n}Exactly n times
{n,}At least n times
{n,m}Between n and m times
*?Zero or more (lazy/non-greedy)
+?One or more (lazy/non-greedy)
??Zero or one (lazy/non-greedy)

Anchors

CommandCopyDescription
^Start of string or line
$End of string or line
\bWord boundary
\BNon-word boundary
\AStart of string (not line)
\ZEnd of string (not line)

Groups and Capturing

CommandCopyDescription
(abc)Capture group
(?:abc)Non-capturing group
(?<name>abc)Named capture group
\1Backreference to group 1
(?=abc)Positive lookahead
(?!abc)Negative lookahead
(?<=abc)Positive lookbehind
(?<!abc)Negative lookbehind

Alternation

CommandCopyDescription
a|bMatch a or b
(cat|dog)Match cat or dog

Special Characters

CommandCopyDescription
\Escape special character
\nNewline
\rCarriage return
\tTab
\0Null character
\x{hh}Character with hex code hh

Flags/Modifiers

CommandCopyDescription
iCase-insensitive matching
gGlobal matching (find all)
mMultiline mode
sDot matches newline
uUnicode mode
xIgnore whitespace and comments

Common Patterns

CommandCopyDescription
^[a-zA-Z0-9]+$Alphanumeric string
^[a-zA-Z]+$Letters only
^[0-9]+$Numbers only
^\d{3}-\d{3}-\d{4}$Phone number (xxx-xxx-xxxx)
^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$Email address
^https?://[^\s]+$URL
^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$Hex color code
^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$IP address
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$Strong password
^[A-Z][a-z]+ [A-Z][a-z]+$Full name (First Last)
^\d{5}(-\d{4})?$US ZIP code
^[0-9]{4}-[0-9]{2}-[0-9]{2}$Date (YYYY-MM-DD)

Username Patterns

CommandCopyDescription
^[a-zA-Z0-9_]{3,16}$Username (3-16 chars)
^@[a-zA-Z0-9_]{1,15}$Twitter handle

File Extensions

CommandCopyDescription
\.txt$Match .txt files
\.(jpg|jpeg|png|gif)$Match image files
\.(pdf|doc|docx)$Match document files

HTML/XML Patterns

CommandCopyDescription
<([a-z]+)([^>]*)>.*?</\1>Match HTML tag
<!--.*?-->Match HTML comment

Number Patterns

CommandCopyDescription
^-?\d+$Integer (positive or negative)
^-?\d*\.?\d+$Decimal number
^\d{1,3}(,\d{3})*$Number with commas
^\$?\d+(\.\d{2})?$Currency amount

Credit Card Patterns

CommandCopyDescription
^4[0-9]{12}(?:[0-9]{3})?$Visa card number
^5[1-5][0-9]{14}$MasterCard number
^3[47][0-9]{13}$American Express number

Social Security

CommandCopyDescription
^\d{3}-\d{2}-\d{4}$US Social Security Number

Time Patterns

CommandCopyDescription
^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$Time (HH:MM 24-hour)
^(0?[1-9]|1[0-2]):[0-5][0-9] (AM|PM)$Time (12-hour with AM/PM)

Whitespace

CommandCopyDescription
^\s*$Empty or whitespace only
\s+One or more whitespace
^\S+$No whitespace

All operations are performed locally in your browser. No data is sent to any server.

About Regex Cheat Sheet

This section will contain detailed, SEO-friendly content about the Regex Cheat Sheet.

In the future, this content will be managed through a headless CMS, allowing you to:

  • Add detailed explanations about how to use this tool
  • Include examples and use cases
  • Provide tips and best practices
  • Add FAQs and troubleshooting guides
  • Update content without touching the code

How to Use

Step-by-step instructions for using the Regex Cheat Sheet will appear here. This content will be fully customizable through the admin panel.

Features

Key features and benefits of this tool will be listed here. All content is editable via the CMS.