Regex Tester
Paste a pattern and test text to see matches highlight instantly, with capture groups, match positions, and flags explained. Whether you are debugging a validation pattern, cleaning up pasted data, or learning regex for the first time, this free regex tester runs entirely in your browser — nothing you type leaves your device.
How to Use the Regex Tester
- Type or paste your pattern into the pattern bar at the top of the tool, without the surrounding slashes. Click a cheat-sheet entry to insert a token at the cursor.
- Set your flags. The
gflag is on by default so you see every match. Toggleifor case-insensitive matching,mfor line-by-line anchors, andsso.also matches newlines. - Paste your test text into the Test String box. Matches highlight in real time, and the match count updates as you type.
- Inspect capture groups in the Match Details table: each row shows the matched text, its index in the string, and the value of every group.
- Fix errors in place. If your pattern is invalid, the error bar shows the JavaScript error message so you can correct the exact token that failed.
Real Use Cases
- Form validation: test an email, phone, or postal-code pattern against valid and invalid samples before shipping it in a signup form.
- Log cleanup: pull IP addresses, dates, or error codes out of pasted log lines with a pattern like
\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b. - Data extraction: pull prices, URLs, or hex colors from a block of text without writing a throwaway script.
- Search-and-replace planning: verify a find pattern matches exactly the lines you intend to change, and nothing else, before running it in your editor.
- Learning regex: change one token at a time and watch the highlights move — the fastest way to build intuition for quantifiers, groups, and anchors.
Frequently Asked Questions
Why is my regex not matching anything?
The most common causes are a missing flag (use the g flag for all matches, not just the first), an unescaped special character such as a dot or parenthesis, and an anchor (^ or $) that does not fit your test text. Check the error bar under the pattern field: an invalid pattern shows its JavaScript error message there.
What do the g, i, m, and s regex flags do?
g (global) finds every match instead of stopping at the first. i makes matching case-insensitive. m makes ^ and $ match the start and end of each line, not just the whole string. s (dotAll) lets . match newline characters too.
What is the difference between greedy and lazy matching?
Greedy quantifiers like .* match as much as possible; lazy ones like .*? match as little as possible. For example, /<div>.*<\/div>/ on a line with two divs matches from the first opening tag to the last closing tag, while /<div>.*?<\/div>/ stops at the first closing tag.
Can I use this regex tester to validate an email address?
Yes. Try /^[\w.+-]+@[\w-]+\.[a-zA-Z]{2,}$/ against sample addresses to see what passes and what fails. Note that no regex can fully validate email addresses per RFC 5322, so use it as a sanity check, not proof an address exists.
Is this regex tester the same as JavaScript, Python, or PCRE regex?
This tester uses JavaScript regular expressions, the flavor built into browsers. Most everyday patterns work the same in Python and PCRE, but lookbehind, named groups, and some escape sequences differ between flavors, so always re-test a pattern in the language you will ship it in.
Does my test text leave my browser?
No. Matching runs entirely in your browser with JavaScript. Your pattern and test string are never sent to a server, so it is safe to test patterns against real log lines or sample data.
Regular Expressions: A Practical Introduction
Regular expressions (regex) are patterns that match text. They're built into virtually every programming language, text editor, and command-line tool. A regex like /\d{3}-\d{4}/ matches phone number patterns like "555-1234". Learning regex is one of the highest-leverage skills in programming — a single regex can replace dozens of lines of string-parsing code.
The basics are straightforward. . matches any character. \d matches any digit. \w matches any word character (letter, digit, underscore). * means "zero or more." + means "one or more." ? means "zero or one." {3} means "exactly 3." [abc] matches any one of a, b, or c. ^ matches the start of a line. $ matches the end.
Where regex gets complex is combining these primitives. /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/ is a basic email validator. It looks intimidating, but break it down piece by piece and each part is simple: "one or more alphanumeric or special characters, then @, then one or more alphanumeric characters with dots, then a dot, then 2+ letters."
Common Regex Patterns
Email validation: /^[\w.+-]+@[\w-]+\.[a-zA-Z]{2,}$/ — catches most valid emails. Note that truly comprehensive email validation via regex is practically impossible due to the RFC 5322 spec's complexity.
URL matching: /https?:\/\/[\w.-]+(?:\.[\w]{2,})(?:\/[^\s]*)?/ — matches http and https URLs with optional paths.
IP address: /\b(?:\d{1,3}\.){3}\d{1,3}\b/ — matches IPv4 addresses (doesn't validate range, so 999.999.999.999 would match).
Date (YYYY-MM-DD): /\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])/ — matches ISO 8601 date format with basic validation.
Phone number (US): /(?:\+1[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}/ — matches various US phone formats like (555) 123-4567, 555-123-4567, +1 555 123 4567.
Regex Performance and Gotchas
Catastrophic backtracking is the biggest performance trap in regex. Patterns like /(a+)+b/ can take exponential time on inputs like "aaaaaaaaaaaaaaac" because the engine tries every possible way to divide the a's between the inner and outer groups before failing. Avoid nested quantifiers on overlapping patterns.
Greedy vs. lazy matching. By default, .* is greedy — it matches as much as possible. .*? is lazy — it matches as little as possible. This matters when parsing HTML: /<div>.*<\/div>/ matches from the first <div> to the last </div> on the line. Add ? to match the closest closing tag instead.
Don't parse HTML with regex. This is a classic mistake. HTML is a context-free grammar that regex fundamentally can't parse correctly. Use a proper HTML parser (DOMParser in browsers, cheerio in Node.js) for anything beyond trivial text extraction.