Regex Tester
Test a regular expression against your own text and see matches, capture groups and errors as you type. Nothing is sent to a server.
Enter the pattern without the surrounding slashes; they are shown as decoration. Flags go in the small field on the right.
Match result
Matches
Without the g flag the first match and its groups are shown; with g, every full match is listed.
Flags in JavaScript
| Flag | Effect | Use it when |
|---|---|---|
g | Find all matches, not just the first | Counting or extracting every occurrence |
i | Ignore letter case | Matching user input |
m | ^ and $ match each line | Scanning multiline logs |
s | Dot also matches newlines | Matching across line breaks |
u | Full Unicode mode | Emoji, property escapes, code points |
y | Sticky match at the current position | Parsing a stream token by token |
Invalid flags throw an error immediately, so a typo here is reported in the result card rather than silently ignored.
A regex is a program written in one line
Every pattern describes a set of strings. Testing is how you check that the set contains what you want and excludes what you fear, especially the empty string and the awkward edge cases.
How the tester evaluates a pattern
The page builds a JavaScript RegExp from the two fields and runs it against the test text. Two details explain most of the output you will see:
- Without
g, the result is the first match plus its numbered capture groups. Group 0 is the whole match; groups 1 and up are the parenthesized parts. - With
g, JavaScript returns an array of full matches only. Capture groups are not included in that array, which is why the group labels disappear when you add the flag.
A pattern that does not compile — an unclosed group, a dangling quantifier, an unknown flag — throws an exception, and the message is shown under the result instead of a match list. That message comes from the browser's engine, so it names the position where parsing failed.
There is no server round trip. The pattern and the text stay in the page, which means you can paste logs or customer data without sending them anywhere.
Syntax quick reference
| Token | Matches | Example |
|---|---|---|
. | Any character except a line break | a.c matches abc |
\d | A digit from 0 to 9 | \d{4} matches 2026 |
\w | Letter, digit or underscore | \w+ matches user_1 |
\s | Space, tab or newline | \s+ collapses gaps |
[abc] | One character from the set | [aeiou] matches a vowel |
[^abc] | One character not in the set | [^0-9] matches a letter |
* | Zero or more of the previous item | ab* matches a and abbb |
+ | One or more | \d+ needs at least one digit |
? | Zero or one, or makes a quantifier lazy | colou?r |
{2,4} | Between two and four repetitions | \d{2,4} |
^ $ | Start and end of the string or line | ^\d+$ |
\b | A word boundary | \bcat\b |
(...) | Capturing group | (\d{3})-(\d{4}) |
(?:...) | Non-capturing group | (?:ab)+ |
| | Alternation | cat|dog |
(?=...) | Positive lookahead | \d+(?=px) |
(?<=...) | Positive lookbehind | (?<=\$)\d+ |
JavaScript's \d matches ASCII digits only, and \w is limited to ASCII letters, digits and underscore. For accented letters or other scripts, use a character class or a Unicode property escape such as \p{L} with the u flag.
Greedy and lazy quantifiers
A quantifier is greedy by default: it takes as much as it can while still allowing the rest of the pattern to match. Adding ? makes it lazy, so it takes as little as possible.
Given <b>one</b> and <b>two</b>, the pattern <b>.*</b> matches the whole string, because the greedy dot runs to the last closing tag. The pattern <b>.*?</b> stops at the first closing tag and matches only <b>one</b>.
Neither pattern is a parser. If the input contains nested tags or attributes with angle brackets, a regular expression will eventually produce the wrong answer; use an HTML parser for HTML.
Anchors, boundaries and multiline text
Anchors do not consume characters; they assert a position. ^ asserts the start of the input, $ the end, and \b a boundary between a word character and a non-word character. Without anchors, a pattern can match a fragment in the middle of a word and still report success.
The m flag changes the meaning of ^ and $: they then match at every line boundary instead of only at the ends of the input. That is convenient for logs and configuration files, and a common source of surprise when a pattern that was anchored suddenly matches each line of a pasted document.
A related trap is $ before a trailing newline. Many engines allow a final line break after $, so a value that looks fully anchored may still accept a stray newline. If the whole string must be validated, use \A-style strictness where available, or trim the input before testing.
Errors that cost real debugging time
- Catastrophic backtracking. Nested quantifiers such as
(a+)+can make the engine explore an exponential number of paths on a failing input. Prefer simpler constructs and test with long, almost-matching strings. - Unescaped metacharacters. A literal dot is
\., a literal dollar sign is\$. Searching for a version number like1.2.3with unescaped dots matches far more than intended. - Forgetting to anchor.
\d{5}finds a ZIP code inside a longer number. Add^and$when the whole field must be a ZIP code. - Assuming dot covers newlines. It does not, unless the
sflag is set. - Using one regex for email or HTML. Both grammars are more complex than a practical pattern can validate. Use a parser or a library.
- Testing only valid input. Half the value of a test suite is the strings that should be rejected: empty, very long, unicode, and near-misses.
When a pattern behaves strangely, shorten it. Remove one group at a time until the match changes, then rebuild from the smallest version that still reproduces the problem.
Related Developer & Security Tools
| Tool | What does it do? | Action |
|---|---|---|
| Base64 Encoder & Decoder | Encode text to Base64 or decode a Base64 string back to plain text. | Base64 Codec → |
| Hash Generator | Create MD5, SHA-1, SHA-256 and SHA-512 hashes from text. | Hash Maker → |
| UUID Generator | Generate random UUID v4 values, one or many at a time. | UUID Maker → |
| Password Generator | Build strong random passwords with length and character options. | Password Maker → |
| Regex Tester | Test a regular expression against sample text and inspect the matches. | Current Page |
| JWT Decoder | Decode a JWT header and payload locally, without sending the token anywhere. | JWT Decode → |
Frequently Asked Questions
String.match behaves. With g it returns an array of full matches and omits capture groups. To read groups for every match, iterate with exec on a global regex.\d{3}-\d{4}. The slashes shown around the field are decoration, and adding real ones would make them literal characters in the pattern.? after the quantifier to make it lazy, or replace .* with a character class that excludes the delimiter you are looking for.(?<=...) and (?<!...) are supported. Very old engines reject them, so test in the browser or runtime that will execute the final pattern.
Rate this Tool
Based on 0 user ratings.