NowTo Tools
Back to Blog
01.03.2026·8 min read

Regex Cheat Sheet with Practical Examples (2026)

Regular expressions (regex) are powerful but notoriously confusing. This cheat sheet focuses on practical, real-world patterns you will actually use, with explanations in plain language. Bookmark this page and use our Regex Tester to try them out.

Basic Syntax Quick Reference

. matches any character. * matches zero or more of the previous character. + matches one or more. ? matches zero or one (optional). \d matches any digit (0-9). \w matches any word character (letters, digits, underscore). \s matches whitespace (space, tab, newline). ^ matches start of string. $ matches end of string.

Character Classes

[abc] matches a, b, or c. [a-z] matches any lowercase letter. [A-Z] matches any uppercase letter. [0-9] matches any digit (same as \d). [^abc] matches anything EXCEPT a, b, or c. Combine them: [a-zA-Z0-9] matches any alphanumeric character.

Quantifiers

{3} matches exactly 3. {2,5} matches 2 to 5. {3,} matches 3 or more. These apply to the previous character or group. Example: \d{3} matches exactly three digits.

Groups and Alternation

(abc) captures the group "abc". (?:abc) non-capturing group. (a|b) matches a OR b. Groups are useful for applying quantifiers to multiple characters: (ha){2} matches "haha".

Practical Example: Email Validation

A simple email pattern: [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} — This matches standard email addresses. It checks for characters before @, a domain name, and a TLD of at least 2 characters. Note: perfect email validation via regex is nearly impossible. For production use, validate the format loosely and confirm via verification email.

Practical Example: URL Matching

Match HTTP/HTTPS URLs: https?://[\w.-]+\.[a-zA-Z]{2,}[/\w.-]* — This matches URLs starting with http:// or https://, followed by a domain name and optional path. For more complete URL matching, include query parameters and fragments.

Practical Example: Phone Numbers

US phone numbers: \(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4} — Matches formats like (555) 123-4567, 555-123-4567, 555.123.4567, and 5551234567.

Practical Example: Password Validation

At least 8 characters with uppercase, lowercase, and digit: ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$ — Uses lookaheads (?=...) to assert multiple conditions without consuming characters.

Practical Example: Extract Data

Extract numbers from text: \d+\.?\d* — Matches integers and decimals. Extract quoted strings: "[^"]*" or '[^']*' — Matches content between quotes.

Test Your Regex

The best way to learn regex is by experimenting. Use NowTo Tools' Regex Tester to write patterns, test against sample text, and see matches highlighted in real-time. It runs in your browser — your test data stays private.

Try these tools for free — no download, no signup required

Explore All Tools