Regex Tester
Test and debug regular expressions with live validation, match highlighting, and detailed explanations. Professional tool for developers.
RegEx Tester & Validator
Test regular expressions with live validation and match highlighting. Perfect for debugging patterns and learning regex.
๐ค Regular Expression
Common Flags:
๐ Test String
๐ฏ Results (0 matches)
Enter pattern and test string
Results will appear here
Quick Reference
Basic Patterns
. - Any character\\d - Any digit\\w - Word character\\s - WhitespaceQuantifiers
+ - One or more* - Zero or more? - Zero or one{n,m} - Between n and mAnchors
^ - Start of string$ - End of string\\b - Word boundary\\B - Non-word boundaryComplete Regular Expressions Guide
๐ What Are Regular Expressions?
Regular expressions (regex) are powerful pattern-matching tools used to search, validate, and manipulate text. They provide a concise way to describe complex text patterns using special characters and syntax rules.
Why Learn Regex?
- โข Data Validation: Email, phone, password validation
- โข Text Processing: Search and replace operations
- โข Log Analysis: Extract specific information from logs
- โข Web Scraping: Parse HTML and extract data
- โข Code Analysis: Find patterns in source code
Real-World Applications
Used in programming languages (JavaScript, Python, Java), text editors (VS Code, Sublime), command-line tools (grep, sed), databases (MySQL, PostgreSQL), and web development frameworks.
๐ฏ How to Use This Tester
Write Your Pattern
Enter your regex pattern in the Pattern field. Start simple with literal text, then add special characters for complex matching.
Set Flags
Use flags to modify behavior: 'g' for global matching, 'i' for case-insensitive, 'm' for multiline mode.
Test Against Text
Enter sample text to see matches highlighted in real-time. View detailed results including match positions and capture groups.
Debug and Refine
Iterate on your pattern, test edge cases, and use our reference guide to learn new syntax elements.
Complete Regex Syntax Reference
๐ Character Classes
.Any character except newline\\dAny digit [0-9]\\DAny non-digit\\wWord char [a-zA-Z0-9_]\\WNon-word character\\sWhitespace [ \\t\\n\\r]\\SNon-whitespace๐ข Quantifiers
*Zero or more+One or more?Zero or one (optional){n}Exactly n times{n,}n or more times{n,m}Between n and m times*?Non-greedy (lazy)โ Anchors & Boundaries
^Start of string/line$End of string/line\\bWord boundary\\BNon-word boundary\\AStart of string only\\ZEnd of string only๐ Groups & Alternatives
(abc)Capturing group(?:abc)Non-capturing groupa|bAlternation (or)\\1Backreference(?=abc)Positive lookahead(?!abc)Negative lookahead๐จ Character Sets
[abc]Any of a, b, or c[^abc]Not a, b, or c[a-z]Lowercase letters[A-Z]Uppercase letters[0-9]Digits[a-zA-Z0-9]Alphanumeric๐ฉ Flags & Modifiers
gGlobal (all matches)iCase insensitivemMultiline modesDot matches newlineuUnicode modeySticky modeCommon Patterns and Real-World Examples
๐ง Validation Patterns
Email Address
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$Validates basic email format with username, @ symbol, domain, and TLD.
Phone Number (US)
^(\\+1[- ]?)?\\(?([0-9]{3})\\)?[- ]?([0-9]{3})[- ]?([0-9]{4})$Matches various US phone number formats: (555) 123-4567, 555-123-4567, +1 555 123 4567.
Strong Password
^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[@$!%*?&])[A-Za-z\\d@$!%*?&]{8,}$Requires 8+ characters with lowercase, uppercase, digit, and special character.
๐ Text Processing Patterns
Extract URLs
https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)Finds HTTP and HTTPS URLs in text content.
Credit Card Numbers
^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13})$Matches Visa, MasterCard, and American Express card formats.
IP Address (IPv4)
^(?:(?: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]?)$Validates IPv4 addresses with proper range checking (0-255 per octet).
Regex Best Practices and Performance Tips
โ Best Practices
๐ฏ Be Specific
Use precise patterns rather than overly broad ones:
.+ (matches everything)[A-Za-z0-9]+ (specific characters)โ Use Anchors
Anchor patterns to prevent unintended matches:
\\d{3} (matches 123 in 123456)^\\d{3}$ (exactly 3 digits)๐ Use Comments and Naming
Document complex patterns and use named groups for clarity. Consider breaking very complex patterns into multiple simpler ones.
๐ซ Common Pitfalls
๐ฅ Catastrophic Backtracking
Avoid nested quantifiers that can cause exponential time complexity:
(a+)+ba+b๐ Greedy vs Non-Greedy
Understand the difference between greedy and lazy quantifiers:
<.+> (matches <a>text</a>)<.+?> (matches <a> only)๐งช Always Test Edge Cases
Test with empty strings, very long inputs, special characters, and malformed data. What works for normal input might fail catastrophically on edge cases.
Frequently Asked Questions
Q: What's the difference between .* and .+?
A: .* matches zero or more of any character (including empty string), while .+ matches one or more (requires at least one character). Use .+ when you need to ensure something exists, .* when optional.
Q: Why isn't my regex matching across multiple lines?
A: By default, . doesn't match newline characters, and ^ and $ only match string start/end. Use the 'm' flag for multiline mode (^ and $ match line boundaries) and 's' flag for dotall mode (. matches newlines).
Q: How do I match a literal special character?
A: Escape special characters with backslashes: \. \+ \* \? \[ \] \( \) \ \^ \$ \| \\. Inside character classes [like this], most characters don't need escaping except ] ^ - and \.
Q: What are capture groups and how do I use them?
A: Capture groups (parentheses) save matched portions for later use. In "Hello (\\w+)", the word after "Hello " is captured as group 1. Use \\1, \\2, etc. to reference captured groups within the same pattern, or access them programmatically in your code.
Q: When should I use regex vs string methods?
A: Use regex for pattern matching, validation, and complex text processing. Use simple string methods (contains, startsWith, etc.) for literal text searches - they're faster and more readable. If you can solve it simply without regex, do so.
Q: How can I make my regex more readable?
A: Break complex patterns into smaller parts, use non-capturing groups (?:...) to organize without creating unnecessary captures, add comments in your code explaining what each part does, and consider using multiple simpler regexes instead of one complex one.
Q: Why is my regex slow on large text?
A: Common causes include catastrophic backtracking from nested quantifiers, overly broad patterns that force excessive backtracking, or missing anchors. Use atomic groups, possessive quantifiers, or break up the text into smaller chunks for processing.
Q: Are regex engines different across programming languages?
A: Yes, while basic syntax is similar, there are differences in supported features, performance, and behavior. JavaScript, Python, Java, and .NET all have slightly different regex implementations. Our tester uses JavaScript's regex engine, so results match browser/Node.js behavior.