Testing regular expressions? Try the free Regex Tester at Orbit2x with live matching and syntax highlighting. Or browse 40+ prebuilt patterns for common tasks.
- 🧪 Regex Tester - Live regex testing with match highlighting
- 📚 Regex Library - 40+ ready-to-use patterns for email, URL, phone, etc.
- 🔍 Grep Tool - Search text with regex patterns
# Basic email (99% cases)
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
# RFC 5322 compliant (more strict)
^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$Test online: Regex Tester
# HTTP/HTTPS URLs
^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)$
# URLs with optional protocol
^(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)$# (123) 456-7890 or 123-456-7890
^\(?([0-9]{3})\)?[-.\s]?([0-9]{3})[-.\s]?([0-9]{4})$
# International format (+1 123 456 7890)
^\+?([0-9]{1,3})\s?([0-9]{3})\s?([0-9]{3})\s?([0-9]{4})$# IPv4 (0.0.0.0 to 255.255.255.255)
^((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]?)$
# IPv6
^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0-1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$# YYYY-MM-DD
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$
# DD/MM/YYYY or MM/DD/YYYY
^(0[1-9]|[12][0-9]|3[01])[\/](0[1-9]|1[0-2])[\/]\d{4}$# Visa (starts with 4)
^4[0-9]{12}(?:[0-9]{3})?$
# MasterCard (starts with 51-55 or 2221-2720)
^5[1-5][0-9]{14}$|^2(?:2(?:2[1-9]|[3-9][0-9])|[3-6][0-9][0-9]|7(?:[01][0-9]|20))[0-9]{12}$
# American Express (starts with 34 or 37)
^3[47][0-9]{13}$Browse all patterns: Regex Library with 40+ Patterns
// Test if string matches pattern
const email = "user@example.com";
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
if (emailRegex.test(email)) {
console.log("✅ Valid email");
} else {
console.log("❌ Invalid email");
}
// Extract matches
const text = "Contact us at support@example.com or sales@example.com";
const matches = text.match(/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g);
console.log(matches);
// ["support@example.com", "sales@example.com"]
// Replace with regex
const cleaned = text.replace(/@example\.com/g, "@newdomain.com");
// Capture groups
const urlRegex = /^(https?):\/\/([^\/]+)(\/.*)?$/;
const url = "https://example.com/path/page";
const [, protocol, domain, path] = url.match(urlRegex);
console.log({ protocol, domain, path });
// { protocol: 'https', domain: 'example.com', path: '/path/page' }import re
# Test if string matches
email = "user@example.com"
email_regex = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
if re.match(email_regex, email):
print("✅ Valid email")
else:
print("❌ Invalid email")
# Find all matches
text = "Contact us at support@example.com or sales@example.com"
matches = re.findall(r'[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}', text)
print(matches)
# ['support@example.com', 'sales@example.com']
# Replace with regex
cleaned = re.sub(r'@example\.com', '@newdomain.com', text)
# Capture groups
url_regex = r'^(https?):\/\/([^\/]+)(\/.*)?$'
url = "https://example.com/path/page"
match = re.match(url_regex, url)
if match:
protocol, domain, path = match.groups()
print(f"Protocol: {protocol}, Domain: {domain}, Path: {path}")<?php
// Test if string matches
$email = "user@example.com";
$emailRegex = '/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/';
if (preg_match($emailRegex, $email)) {
echo "✅ Valid email\n";
} else {
echo "❌ Invalid email\n";
}
// Find all matches
$text = "Contact us at support@example.com or sales@example.com";
preg_match_all('/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/', $text, $matches);
print_r($matches[0]);
// Array ( [0] => support@example.com [1] => sales@example.com )
// Replace with regex
$cleaned = preg_replace('/@example\.com/', '@newdomain.com', $text);
// Capture groups
$urlRegex = '/^(https?):\/\/([^\/]+)(\/.*)?$/';
$url = "https://example.com/path/page";
if (preg_match($urlRegex, $url, $matches)) {
echo "Protocol: {$matches[1]}, Domain: {$matches[2]}, Path: {$matches[3]}\n";
}
?>package main
import (
"fmt"
"regexp"
)
func main() {
// Test if string matches
email := "user@example.com"
emailRegex := regexp.MustCompile(`^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`)
if emailRegex.MatchString(email) {
fmt.Println("✅ Valid email")
} else {
fmt.Println("❌ Invalid email")
}
// Find all matches
text := "Contact us at support@example.com or sales@example.com"
pattern := regexp.MustCompile(`[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}`)
matches := pattern.FindAllString(text, -1)
fmt.Println(matches)
// [support@example.com sales@example.com]
// Replace with regex
cleaned := pattern.ReplaceAllString(text, "REDACTED")
// Capture groups
urlRegex := regexp.MustCompile(`^(https?):\/\/([^\/]+)(\/.*)?$`)
url := "https://example.com/path/page"
groups := urlRegex.FindStringSubmatch(url)
if len(groups) > 0 {
fmt.Printf("Protocol: %s, Domain: %s, Path: %s\n", groups[1], groups[2], groups[3])
}
}| Pattern | Matches | Example |
|---|---|---|
. |
Any character except newline | a.c matches "abc", "a1c" |
\d |
Any digit (0-9) | \d{3} matches "123" |
\D |
Any non-digit | \D+ matches "abc" |
\w |
Word character (a-z, A-Z, 0-9, _) | \w+ matches "hello_123" |
\W |
Non-word character | \W+ matches "!@#" |
\s |
Whitespace (space, tab, newline) | \s+ matches " " |
\S |
Non-whitespace | \S+ matches "hello" |
[abc] |
Any of a, b, or c | [aeiou] matches vowels |
[^abc] |
Not a, b, or c | [^0-9] matches non-digits |
[a-z] |
Range a to z | [A-Z]+ matches "HELLO" |
| Pattern | Matches | Example |
|---|---|---|
* |
0 or more | a* matches "", "a", "aaa" |
+ |
1 or more | a+ matches "a", "aaa" |
? |
0 or 1 | colou?r matches "color", "colour" |
{n} |
Exactly n | \d{3} matches "123" |
{n,} |
n or more | \d{3,} matches "123", "1234" |
{n,m} |
n to m | \d{2,4} matches "12", "123", "1234" |
| Pattern | Matches | Example |
|---|---|---|
^ |
Start of string | ^Hello matches "Hello world" |
$ |
End of string | world$ matches "Hello world" |
\b |
Word boundary | \bcat\b matches "cat" not "catch" |
\B |
Non-word boundary | \Bcat\B matches "concatenate" |
| Pattern | Purpose | Example |
|---|---|---|
(abc) |
Capture group | (\d{3})-(\d{4}) captures "123-4567" |
(?:abc) |
Non-capturing group | (?:https?):\/\/ |
(a|b) |
Alternation (OR) | (cat|dog) matches "cat" or "dog" |
(?=abc) |
Positive lookahead | \d+(?= dollars) matches "10" in "10 dollars" |
(?!abc) |
Negative lookahead | \d+(?! dollars) |
Practice with: Regex Tester
const email = "user@example.com";
const domain = email.match(/@(.+)$/)[1];
console.log(domain); // "example.com"# At least 8 chars, 1 uppercase, 1 lowercase, 1 number, 1 special char
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$const tweet = "Learning #regex is fun! #coding #javascript";
const hashtags = tweet.match(/#\w+/g);
console.log(hashtags); // ["#regex", "#coding", "#javascript"]const html = "<p>Hello <strong>world</strong></p>";
const text = html.replace(/<[^>]*>/g, "");
console.log(text); // "Hello world"# #RGB or #RRGGBB
^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$const text = "I have 5 apples and 10 oranges";
const numbers = text.match(/\d+/g);
console.log(numbers); // ["5", "10"]const camelCase = "myVariableName";
const snakeCase = camelCase.replace(/([A-Z])/g, "_$1").toLowerCase();
console.log(snakeCase); // "my_variable_name"# Visa, MasterCard, Amex, Discover
^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|6(?:011|5[0-9]{2})[0-9]{12})$-
Use specific patterns
# ✅ Good - specific \d{3}-\d{3}-\d{4} # ❌ Bad - too generic .*-.*-.*
-
Anchor patterns
# ✅ Good - anchored ^https?:\/\/ # ❌ Bad - searches entire string https?:\/\/
-
Use non-capturing groups
# ✅ Good - non-capturing (?:https?):\/\/ # ❌ Slower - capturing (https?):\/\/
-
Avoid catastrophic backtracking
# ❌ DANGEROUS - exponential time! (a+)+b # ✅ Better a+b
-
Don't use regex for nested structures
# ❌ BAD - Use HTML parser <div>(.*)</div> # ✅ Use DOMParser or cheerio instead
- Regex Tester - Live testing with match highlighting
- Regex Library - 40+ prebuilt patterns
- String Case Converter - Convert camelCase, snake_case, etc.
- Text Diff Tool - Compare text with regex support
- Regex101 - Detailed explanations
- RegexOne - Interactive tutorial
- MDN Regex Guide
- Orbit2x Regex Tester - Clean, fast UI
- Regex101 - Full explanation
- RegExr - Visual tester
A:
- Greedy (
*,+): Match as much as possible - Lazy (
*?,+?): Match as little as possible
const html = "<div>foo</div><div>bar</div>";
// Greedy - matches entire string
html.match(/<div>.*<\/div>/)[0];
// "<div>foo</div><div>bar</div>"
// Lazy - matches first occurrence
html.match(/<div>.*?<\/div>/)[0];
// "<div>foo</div>"A: Use the s (dotall) flag:
// Without s flag - doesn't match newlines
/line1.line2/.test("line1\nline2"); // false
// With s flag - matches newlines
/line1.line2/s.test("line1\nline2"); // trueA: They're equivalent in ASCII. \w also matches Unicode letters in some engines.
A: Use backslash \:
# Match literal dot
\.
# Match literal parentheses
\(\)
# Match literal backslash
\\- JSON Formatter - Format and validate JSON
- SQL Formatter - Beautify SQL queries
- XML Formatter - Format XML documents
- All Text Tools - Complete text processing toolkit
Made with ❤️ by Orbit2x - Free Developer Tools
Try now: Regex Tester • 40+ Patterns