Common Regular Expression Patterns and Examples
💡Regular expressions (regex) are patterns used to match text. Below are the most common patterns developers use daily — copy any pattern and test it instantly in the regex tester.
Patterns Reference
Email address
/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/Matches a standard email address
⚠ Doesn't validate TLD existence — use server-side validation for critical inputs
URL
/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b/Matches http and https URLs
https://example.com, http://www.site.org/path?q=1⚠ Doesn't match bare domains without protocol (e.g. example.com)
Integer number
/^-?\d+$/Matches positive or negative whole numbers
42, -7, 0⚠ Doesn't match floats like 3.14 — use decimal pattern for those
Decimal number
/^-?\d+(\.\d+)?$/Matches integers and decimal numbers
3.14, -0.5, 100⚠ Doesn't match numbers starting with a dot like .5
URL slug
/^[a-z0-9]+(?:-[a-z0-9]+)*$/Matches lowercase URL-safe slugs with hyphens
my-page, json-formatter, tool123⚠ Rejects uppercase and underscores — normalize input before validating
Whitespace trim
/^\s+|\s+$/Matches leading and trailing whitespace (use with /g flag to replace both)
hello , tabs ⚠ Without /g flag only removes one side — use str.trim() in most JS cases
Simple password
/^(?=.*[A-Z])(?=.*\d).{8,}$/Matches strings with 8+ chars, at least one uppercase letter and one digit
Password1, MyPass9word⚠ Doesn't require special characters — adjust lookaheads for stricter requirements
Test Any Pattern in Your Browser
Common Regex Mistakes
Forgetting to escape special characters
Characters like . * + ? ( ) [ ] { } \ ^ $ | have special meaning in regex. Use a backslash to match them literally: \. matches a dot.
Missing anchors (^ and $)
Without ^ and $, the pattern can match anywhere in the string. /\d+/ matches the digits inside "abc123xyz". Add anchors to require a full-string match.
Greedy vs lazy quantifiers
* and + are greedy — they match as much as possible. Add ? to make them lazy: *? matches as little as possible. Important when parsing nested or repeated structures.
Related Guides
Frequently Asked Questions
What are regex anchors?
^ matches the start of a string and $ matches the end. Without them, your pattern can match anywhere inside the input — add anchors when you need a full-string match.
What is the difference between greedy and lazy quantifiers?
Greedy quantifiers (*, +) match as much as possible. Lazy quantifiers (*?, +?) match as little as possible. Use lazy when parsing nested or delimited structures.
Should I use a regex library or write patterns manually?
For well-known formats (email, URL, phone), use a tested library or pattern from this guide. Write custom patterns only for domain-specific formats unique to your app.
All tools run in your browser. Your data never leaves your device.