Free tool · Developer tools
Regex tester
Type a regular expression and some test text, and every match lights up as you type. A table lists each match with its position and capture groups, flags switch on with one tap, and a runaway pattern is stopped instead of freezing the page.
- Free
- No sign-up
- Runs in your browser
2 matchesFirst at position 20
- /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d…/g
- Named: year, month, day
- First match
- "2026-12-01"
- Groups
- 3 (3 named)
- Flags
- g
| # | Position | Match | 1: year | 2: month | 3: day |
|---|---|---|---|---|---|
| 1 | 20-30 | "2026-12-01" | "2026" | "12" | "01" |
| 2 | 40-50 | "2026-11-23" | "2026" | "11" | "23" |
How to use the Regex Tester
- Type the pattern into Regular expression, without the surrounding slashes.
- Tick the Flags you need; g is on so that every match is found.
- Paste or type the Test text. Matches are highlighted and listed in the table below the result.
- Press Copy as /regex/ to take the pattern as a JavaScript literal with its flags.
How do I test a regular expression?
Type the pattern in the first box and the text you want to search in the second; the result updates a moment after you stop typing. The count at the top tells you how many matches there are and where the first one starts, the highlighted text shows each match in place, and the table gives the exact characters of every match and group, with line breaks and tabs spelled out as \n and \t so nothing hides.
The example pattern (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}) looks for dates written as year, month and day. In the sample text it finds 2 matches, at positions 20 and 40 (counting from 0). The first one splits into year = 2026, month = 12, day = 01. It skips "2026-1-5" and "26-11-23" on purpose: \d{4} demands exactly four digits and \d{2} exactly two, so a date with a one-digit month or a two-digit year is not a match. Testing against lines that should fail is as useful as testing lines that should pass.
An invalid pattern shows the error message from the browser's own regular expression engine, such as an unterminated group or a quantifier with nothing to repeat. That message is the same one your JavaScript code would throw, so fixing it here fixes it there.
What do the regex flags g, i, m, s, u, v, y and d do?
Flags change how the whole pattern is read. They are written after the closing slash in JavaScript, as in /cat/gi, and you can combine them freely, except u and v, which cannot be used together because v already includes u. The table runs each flag on a short text and counts the matches with and without it.
| Flag | What it does | Pattern | Text | Matches without | Matches with |
|---|---|---|---|---|---|
g | Finds every match, not just the first | /cat/ | Cat cat\ncat CAT | 1 | 2 |
i | Ignores upper and lower case | /cat/ | Cat cat\ncat CAT | 2 | 4 |
m | Lets ^ and $ match at the start and end of each line | /^cat/ | Cat cat\ncat CAT | 0 | 1 |
s | Lets the dot match a line break too | /cat.cat/ | Cat cat\ncat CAT | 0 | 1 |
u | Reads the pattern as Unicode code points and enables \p{...} classes | /\p{Lu}/ | Cat cat\ncat CAT | 0 | 4 |
v | Unicode sets: everything u does plus set operations such as -- (compared with u here) | /[\p{L}--[a-z]]/ | Cat cat\ncat CAT | invalid | 4 |
y | Sticky: each match must start exactly where the last one ended | /cat ?/ | cat cat, cat | 3 | 2 |
The d flag adds the start and end position of every group to the match result your code receives. This tester shows positions for every match either way, so turning d on changes nothing in the table, but it is there so you can check that your browser supports it before you use it. A flag the browser does not know is greyed out with a note under the flag list.
How do capture groups and named groups work?
Round brackets do two jobs: they group part of a pattern so a quantifier applies to all of it, and they capture the text that part matched. Groups are numbered from 1 by their opening bracket, left to right. Write (?<name>...) to give a group a name, which makes code easier to read and survives adding another group in front. Write (?:...) when you only need the grouping and not the capture.
A group that did not take part in the match has no value at all, which is different from an empty string. The pattern (a)|(b) run on the text "b" gives (no match) and "b": the first group belongs to the branch that was not used. The table marks such groups "(no match)", so you can tell them apart from a group that matched zero characters.
Quantifiers are greedy unless told otherwise: + and * take as much text as they can and give back only what the rest of the pattern needs. On <b>bold</b> and <i>it</i>, the pattern <.+> finds 1 match, the whole line from the first < to the last >. Add a question mark to make it lazy: <.+?> stops at the first possible > and finds 4 separate tags. A negated class such as <[^>]+> gives the same 4, and because it can never step past a closing bracket, it states the intent more plainly than a lazy dot.
To match a character that has a special meaning, put a backslash in front of it. A bare dot matches any character, so 3.5 finds 2 matches in "3.5 and 325", while 3\.5 finds 1. The same goes for brackets, the plus sign, the question mark, the star, the caret, the dollar sign and the pipe.
Why does my regex work here but not in another language?
Because each language ships its own engine, and the engines disagree on details. This tester uses the JavaScript engine of the browser you are reading this in, so its answers hold for code that runs in browsers and JavaScript runtimes. Two differences catch people moving between JavaScript and Python. Python writes a named group as (?P<name>...), a form JavaScript rejects, while JavaScript uses (?<name>...). And the Python documentation says a lookbehind must match strings of a fixed length, so (?<=\d+) is refused there; the engine here accepts it, finding 2 matches of (?<=\d+)px in "width: 120px; gap: 8px".
Some patterns never finish. Nested repeats such as (a+)+$ can try an enormous number of ways to split the text when the end does not match, which is called catastrophic backtracking. A page that ran the pattern directly would freeze. This tester runs it in a separate background worker and stops it after 1.5 seconds with a message, so you can fix the pattern without losing your text.
For replacing text with these patterns, the find and replace tool takes the same JavaScript syntax and fills in $1 and named groups in the replacement.
Use it with
- JSON Formatter: format and validate JSON.
- JavaScript Beautifier: format or minify JS.
- Remove Duplicate Lines: clean lists of repeated lines.
Questions
How do I test a regex online?
Type the pattern and the test text above; matches are highlighted as you type and listed with their groups. The sample date pattern finds 2 matches in the example text.
What does the g flag do?
It makes the search global: every match is found instead of only the first. On "Cat cat\ncat CAT", /cat/ finds 1 match and /cat/g finds 2.
Why does my regex match nothing?
Common causes are case (add i), ^ and $ meaning the whole text instead of each line (add m), a dot or bracket that needs a backslash, or syntax from another language. The table and the error message show which.
How do I match a literal dot or bracket?
Put a backslash before it: \. matches a dot, \[ a bracket. Without the backslash a dot matches any character.
What is catastrophic backtracking?
A pattern with nested repeats, such as (a+)+$, that tries a huge number of ways to match and seems to hang. This tester stops it after 1.5 seconds; make the inner part more specific to fix it.
Is my test text sent anywhere?
No. The pattern runs in a background worker inside this page, on your device. Nothing you type is uploaded.
Sources
The tool's results are computed in your browser by the code on this page, using the sources listed above; the explanations are checked against the tool's own output.