Live pattern matching with explanations, a pattern library, and code generation for JavaScript, Python, Go, and Java. All processing happens in your browser—fast, private, and free.
See matches highlighted in real-time as you type your pattern and test string
Understand each part of your regex with detailed token-by-token explanations
Generate ready-to-use code for JavaScript, Python, Go, and Java
Common patterns for email, URL, phone, dates, and more - ready to use
A powerful browser-based tool for testing, debugging, and learning regular expressions. Features live matching, pattern explanations, code generation for JavaScript, Python, Go, and Java, and a comprehensive pattern library. All processing happens locally—your data never leaves your device.
The Regex Tester features a comprehensive layout with pattern input, test string, match results, and powerful tools like pattern explanation and code generation.
The pattern input is where you enter your regular expression. The tool validates your pattern in real-time and shows any syntax errors immediately. You can toggle regex flags (global, case-insensitive, multiline, etc.) using the buttons next to the input.
Enter or paste the text you want to test your pattern against. Matches are highlighted in real-time as you type. Different colors indicate different capture groups, making it easy to see what each part of your pattern matches.
The results panel shows all matches found, including their position in the text, captured groups, and named groups if any. Each match is expandable to show detailed information about what was captured.
Your regex patterns and test data never leave your browser. Perfect for testing patterns with sensitive data like passwords, API keys, or personal information.
Comprehensive documentation for regex syntax. Click to expand each section for detailed explanations, examples, and tips.
Character classes let you match specific sets of characters. They're the building blocks of most regex patterns, from matching single characters to complex character ranges.
Most characters match themselves exactly. Letters, numbers, and many symbols are matched literally in your pattern.
abc123The dot matches any single character except newline. With the 's' flag, it also matches newlines.
.Square brackets define a set of characters to match. Any single character from the set will match.
[abc] or [a-z]\w matches any word character (letters, digits, underscore). Equivalent to [a-zA-Z0-9_].
\w and \W\d matches any digit character (0-9). \D matches any non-digit character.
\d and \D\s matches any whitespace character (space, tab, newline, carriage return, form feed). \S matches non-whitespace.
\s and \SQuantifiers specify how many times a character or group should be matched. They're essential for matching variable-length patterns like words, numbers, or repeated structures.
The asterisk matches the preceding element zero or more times. It's greedy by default, matching as much as possible.
*The plus sign matches the preceding element one or more times. Unlike *, it requires at least one occurrence.
+The question mark makes the preceding element optional - it matches zero or one time.
?Curly braces with a single number match exactly that many occurrences of the preceding element.
{n}Curly braces with two numbers match between n and m occurrences (inclusive).
{n,m}Curly braces with a number and comma match n or more occurrences.
{n,}By default, quantifiers are greedy (match as much as possible). Add ? to make them lazy (match as little as possible).
*? +? ?? {n,m}?Anchors don't match characters - they match positions in the string. Use them to ensure your pattern matches at specific locations like the start of a line or at word boundaries.
The caret matches the position at the start of the string. With the 'm' flag, it also matches after each newline.
^The dollar sign matches the position at the end of the string. With the 'm' flag, it also matches before each newline.
$\b matches the boundary between a word character and a non-word character. It's zero-width, meaning it doesn't consume characters.
\b\B matches any position that is NOT a word boundary. Useful for matching within words.
\BGroups let you treat multiple characters as a single unit. Capturing groups also save the matched text for later use in replacements or backreferences.
Parentheses create a capturing group. The matched content is saved and can be referenced with $1, $2, etc. in replacements.
(pattern)Named groups let you reference captures by name instead of number. More readable and maintainable.
(?<name>pattern)When you need grouping but don't need to capture, use non-capturing groups. They're slightly faster and don't affect group numbering.
(?:pattern)Backreferences match the same text that was captured by an earlier group. Useful for matching repeated patterns.
\1, \2, ... or \k<name>The pipe character acts as an OR operator, matching either the pattern before or after it.
a|bLookarounds are zero-width assertions that check for patterns without including them in the match. They're powerful for complex matching conditions.
Matches the current position only if the pattern ahead matches. Doesn't consume characters.
(?=pattern)Matches the current position only if the pattern ahead does NOT match.
(?!pattern)Matches the current position only if the pattern behind matches. The lookbehind itself isn't part of the match.
(?<=pattern)Matches the current position only if the pattern behind does NOT match.
(?<!pattern)Flags modify how the regex engine interprets and applies your pattern. They're essential for case-insensitive matching, multiline text, and Unicode support.
Without the global flag, regex stops after the first match. The global flag finds all matches in the string.
/pattern/gMakes the pattern case-insensitive. 'a' will match both 'a' and 'A'.
/pattern/iChanges the behavior of ^ and $. They match the start/end of each line, not just the string.
/pattern/mMakes the dot (.) match newline characters too. Normally, dot matches everything EXCEPT newlines.
/pattern/sEnables full Unicode matching. Required for matching Unicode characters and properties correctly.
/pattern/uReady-to-use regex patterns for common validation, extraction, and formatting tasks. Click on any pattern in the Regex Tester to load it instantly.
Validates email addresses with common formats. Matches most real-world email addresses.
^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,}$Matches HTTP and HTTPS URLs with optional path. Captures domain components.
^(https?:\/\/)?([\w.-]+)\.([a-z]{2,})(\/[\w./-]*)?$Matches US phone numbers in various formats including parentheses and separators.
^\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$Matches international phone numbers in E.164 format.
^\+?[1-9]\d{1,14}$Validates IPv4 addresses with proper range checking (0-255 for each octet).
^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$Matches full IPv6 addresses (without shorthand notation).
^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$Matches ISO 8601 date format with basic validation for month and day ranges.
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$Matches 24-hour time format with optional seconds.
^([01]\d|2[0-3]):([0-5]\d)(?::([0-5]\d))?$Matches 3 or 6 digit hex color codes with optional # prefix.
^#?([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$Matches UUID/GUID format with version and variant validation.
^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$Alphanumeric username starting with a letter, 3-16 characters, allowing underscores and hyphens.
^[a-zA-Z][a-zA-Z0-9_-]{2,15}$Matches HTML tags with their content. Captures tag name and inner content.
<([a-z][a-z0-9]*)\b[^>]*>(.*?)<\/\1>Extracts markdown links, capturing link text and URL separately.
\[([^\]]+)\]\(([^)]+)\)Matches single or double quoted strings, handling escaped quotes.
(["'])(?:(?!\1)[^\\]|\\.)*\1Finds repeated words like 'the the' or 'is is'. Useful for proofreading.
\b(\w+)\s+\1\bMatches URL-friendly slugs with lowercase letters, numbers, and hyphens.
^[a-z0-9]+(?:-[a-z0-9]+)*$Matches spaces or tabs at the end of lines. Use with multiline flag.
[ \t]+$Matches 2 or more consecutive spaces. Use for normalizing whitespace.
{2,}Matches Visa, Mastercard, and American Express card numbers (without spaces).
^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13})$Requires at least 8 characters with uppercase, lowercase, number, and special character.
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$Regular expressions are essential for many development tasks. Here are common scenarios where regex can save you hours of manual work.
Validate user input in real-time before form submission. Check email formats, phone numbers, passwords, and custom fields.
Parse log files to extract timestamps, IP addresses, error codes, and other structured data from unstructured text.
Clean and transform text data by removing unwanted characters, normalizing formats, or extracting specific patterns.
Reformat data from one structure to another using capture groups and replacement patterns.
Detect and filter potentially malicious input, validate security-sensitive data, and sanitize user content.
Search and replace across codebases using regex to rename variables, update API calls, or migrate patterns.
Writing effective regex takes practice. Here are essential tips to help you write better patterns.
Build your regex incrementally. Start with a simple pattern and add complexity as needed.
Use ^ and $ to ensure your pattern matches the entire string, not just a part of it.
Avoid .* when possible. Use specific character classes like \d or \w for better precision.
Always test with empty strings, very long strings, and unexpected input.
Avoid nested quantifiers like (a+)+ which can cause catastrophic backtracking.
Use (?:...) when you need grouping but don't need to capture the match.