Regex Cheat Sheet: Common Patterns Explained
Regular expressions (regex) are incredibly powerful tools for matching, parsing, and validating text input. However, their syntax is notoriously dense and hard to parse at a glance. Having a quick-reference guide for standard search patterns can save developers hours of trial and error. Below is a cheat sheet of the five most common regular expressions used in modern web applications.
1Email Validation
What it matches: Validates the general structure of email addresses. It ensures characters are present before the @ symbol, followed by a valid domain host, and a top-level domain (TLD) extension that is at least 2 letters long.
user.name@example.com, hello_world123@quietbench.devuser@example, @domain.com2URL Matching
What it matches: Matches standard web URLs beginning with either http:// or https://. It supports optional subdomains, paths, parameters, anchors, and queries.
https://quietbench.dev/regex-tester?q=active, http://www.google.com/ftp://files.example.com, quietbench.dev (no protocol)3US Phone Number
What it matches: Validates 10-digit telephone numbers in standard US formats. It handles an optional 3-digit area code enclosed in parentheses, followed by digits separated by dashes, dots, spaces, or nothing at all.
(555) 123-4567, 555-123-4567, 5551234567555-12-34, +1-555-123-456784IPv4 Address
What it matches: Matches IP addresses in dotted-decimal format. The expression verifies that all four segments (octets) of the address contain numbers falling strictly within the allowed range of 0 to 255.
192.168.1.100, 127.0.0.1256.0.0.1 (above range), 192.168.1 (incomplete)5Hex Color Code
What it matches: Validates HTML/CSS hex color codes. The expression matches an optional leading hash # followed by either a 6-digit hex representation (two digits each for red, green, and blue) or a shorthand 3-digit version.
#3b82f6, #FFF, 000#GGGGGG (invalid letters), #FF12 (invalid length)Need to test or write a custom regex pattern?
Test regular expressions with live highlighting, test suites, and plain-English explanations.