Test regular expressions with live matching, capture groups, and replace mode. All processing runs in your browser.
g (global) flag is enabled by default to find all matches. Enable i for case-insensitive matching, m for multiline mode, or s to make the dot match newlines.$1, $2 for captured groups) and click "Replace" to see the result.Regular expressions (regex or regexp) are powerful sequences of characters that define search patterns. They are used across virtually every programming language and text editor for tasks like:
A simple regex like \d+ matches one or more digits, while [A-Za-z]+ matches one or more letters. You can combine these building blocks to create patterns that match complex text structures. Regular expressions are supported in JavaScript, Python, PHP, Java, C#, Ruby, Go, and most other programming languages.
| Pattern | Description | Example |
|---|---|---|
| . | Any character except newline | a.c matches "abc", "a1c" |
| * | Zero or more of the preceding element | ab*c matches "ac", "abc", "abbc" |
| + | One or more of the preceding element | ab+c matches "abc", "abbc" but not "ac" |
| ? | Zero or one of the preceding element | colou?r matches "color", "colour" |
| ^ | Start of string (or line in multiline mode) | ^Hello matches "Hello world" |
| $ | End of string (or line in multiline mode) | world$ matches "Hello world" |
| [abc] | Character class: matches a, b, or c | [aeiou] matches vowels |
| [^abc] | Negated class: any char except a, b, c | [^0-9] matches non-digits |
| {n,m} | Between n and m repetitions | \d{2,4} matches 2 to 4 digits |
| () | Capture group | (\w+)@(\w+) captures user and domain |
| | | Alternation (OR) | cat|dog matches "cat" or "dog" |
| \d | Digit (equivalent to [0-9]) | \d{3} matches "123" |
| \w | Word character (letter, digit, underscore) | \w+ matches "hello_123" |
| \s | Whitespace (space, tab, newline) | \s+ matches spaces between words |
| \b | Word boundary | \bcat\b matches "cat" but not "category" |
| (?=...) | Positive lookahead | \d+(?= dollars) matches "100" in "100 dollars" |
| (?!...) | Negative lookahead | \d+(?! dollars) matches digits not before " dollars" |
| (?:...) | Non-capturing group | (?:ab)+ matches "abab" without capturing |
[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}
Matches standard email addresses like [email protected]. Validates the local part, @ symbol, domain, and TLD.
https?:\/\/[^\s/$.?#].[^\s]*
Matches HTTP and HTTPS URLs. Captures the protocol, domain, path, and query parameters.
\b(?:\d{1,3}\.){3}\d{1,3}\b
Matches IPv4 addresses like 192.168.1.1. Each octet can be 1-3 digits. Does not validate the 0-255 range.
\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}
Matches US phone numbers in various formats: (555) 123-4567, 555-123-4567, 555.123.4567.
\d{4}[-/]\d{2}[-/]\d{2}
Matches dates in ISO format like 2026-03-19 or 2026/03/19. Accepts hyphens or slashes as separators.
<([a-z][a-z0-9]*)\b[^>]*>(.*?)<\/\1>
Matches opening and closing HTML tags with content between them. Uses a backreference to match the closing tag.
#(?:[0-9a-fA-F]{3}){1,2}\b
Matches 3-digit and 6-digit hex color codes like #fff, #FF5733, #e94560.
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[\W_]).{8,}$
Validates strong passwords: at least 8 characters with uppercase, lowercase, digit, and special character.
^[a-zA-Z0-9_-]{3,20}$
Validates usernames: 3-20 characters, letters, numbers, underscores, and hyphens only.
\s{2,}
Matches two or more consecutive whitespace characters. Useful for cleaning up text with extra spaces.
A regular expression is a sequence of characters that defines a search pattern. Regex is used for string matching, validation, search-and-replace, and text extraction in programming and text editors. Most programming languages including JavaScript, Python, PHP, and Java support regex natively.
Yes, absolutely. All processing happens entirely in your browser using JavaScript. No data is sent to any server. Your text and regex patterns never leave your computer. You can even use this tool offline once the page is loaded.
This tool uses the native JavaScript RegExp engine built into your browser. It supports all standard regex features including capture groups, named groups, lookaheads, lookbehinds (in modern browsers), and Unicode properties. JavaScript regex syntax is very similar to most other languages.
Capture groups are created by placing part of a regex pattern inside parentheses (). When a match is found, the text matched by each group is captured separately, allowing you to extract specific parts of the matched text. Use $1, $2, etc. in replacement strings to reference captured groups. Non-capturing groups (?:...) group without capturing.
JavaScript regex syntax is very similar to regex in most other languages (Python, PHP, Java, C#). Most basic and intermediate patterns work the same way across languages. However, some advanced features like possessive quantifiers (++), atomic groups ((?>...)), or conditional patterns are not supported in JavaScript regex.