Regular Expression Cheat Sheet

Detailed regular expression patterns guide

Regular Expression Cheat Sheet

Comprehensive reference guide for Regular Expressions with common patterns. Click the copy button to copy any pattern.

99
Total Commands
99
Filtered Results

Character Classes

CommandCopyDescription
.Any character except newline
\dAny digit [0-9]
\DAny non-digit
\wWord character [a-zA-Z0-9_]
\WNon-word character
\sWhitespace character
\SNon-whitespace character
[abc]Any of a, b, or c
[^abc]Not a, b, or c
[a-z]Character between a and z
[A-Z]Character between A and Z
[0-9]Any digit
[a-zA-Z]Any letter

Quantifiers

CommandCopyDescription
*Zero or more
+One or more
?Zero or one
{n}Exactly n times
{n,}n or more times
{n,m}Between n and m times
*?Zero or more (lazy)
+?One or more (lazy)
??Zero or one (lazy)
{n,}?n or more (lazy)
{n,m}?n to m (lazy)

Anchors

CommandCopyDescription
^Start of string/line
$End of string/line
\bWord boundary
\BNot word boundary
\AStart of string
\ZEnd of string
\zAbsolute end of string

Groups and Capturing

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

Alternation

CommandCopyDescription
a|ba or b
(cat|dog)cat or dog

Special Characters

CommandCopyDescription
\Escape special character
\nNewline
\rCarriage return
\tTab
\vVertical tab
\fForm feed
\0Null character
\xhhHex character
\uhhhhUnicode character

Flags/Modifiers

CommandCopyDescription
iCase-insensitive
gGlobal match
mMultiline
sDot matches newline
uUnicode
xExtended (ignore whitespace)
ySticky

Email Validation

CommandCopyDescription
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$Basic email validation
^[\w.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$Email with subdomains

URL Validation

CommandCopyDescription
^https?://[^\s]+$Basic URL
^(https?|ftp)://[^\s/$.?#].[^\s]*$URL with protocols
^https?://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$Complete URL validation

Phone Numbers

CommandCopyDescription
^\d{3}-\d{3}-\d{4}$US phone (xxx-xxx-xxxx)
^\(?\d{3}\)?[- ]?\d{3}[- ]?\d{4}$Flexible US phone
^\+?\d{1,3}?[- ]?\(?\d{1,4}\)?[- ]?\d{1,4}[- ]?\d{1,9}$International phone

Dates

CommandCopyDescription
^\d{4}-\d{2}-\d{2}$Date (YYYY-MM-DD)
^\d{2}/\d{2}/\d{4}$Date (MM/DD/YYYY)
^(0[1-9]|1[0-2])/(0[1-9]|[12]\d|3[01])/\d{4}$Validated MM/DD/YYYY

Time

CommandCopyDescription
^([01]?[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)

IP Addresses

CommandCopyDescription
^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$IPv4 address
^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$Valid IPv4

Credit Cards

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

Passwords

CommandCopyDescription
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$Strong password (8+ chars, upper, lower, digit)
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&]).{8,}$Strong password with special char

Usernames

CommandCopyDescription
^[a-zA-Z0-9_]{3,16}$Username (3-16 alphanumeric)
^[a-zA-Z][a-zA-Z0-9_]{2,15}$Username (starts with letter)

Colors

CommandCopyDescription
^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$Hex color code
^rgb\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*\)$RGB color

Numbers

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

HTML/XML

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

Files

CommandCopyDescription
\.txt$Text file
\.(jpg|jpeg|png|gif)$Image file
\.(pdf|doc|docx|txt)$Document file

Social Media

CommandCopyDescription
^@[a-zA-Z0-9_]{1,15}$Twitter handle
^#[a-zA-Z0-9_]+$Hashtag

Common Patterns

CommandCopyDescription
^[a-zA-Z\s]+$Letters and spaces only
^[a-zA-Z0-9]+$Alphanumeric only
^\s*$Empty or whitespace
^(?!\s*$).+Not empty

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

About Regular Expression Cheat Sheet

This section will contain detailed, SEO-friendly content about the Regular Expression 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 Regular Expression 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.