Regex Tester
Test a JavaScript regular expression against your text and see every match and capture group live.
- #1 ada@knidox.comindex 8
- group 1: ada
- group 2: knidox
- group 3: com
- #2 grace@example.orgindex 26
- group 1: grace
- group 2: example
- group 3: org
A regex tester runs a regular expression against text and shows what it matches. With the global flag on, the pattern (\w+)@(\w+)\.(\w+) finds two emails in “Contact ada@knidox.com or grace@example.org”, and each match exposes three capture groups — the name, domain, and top-level suffix.
What a regular expression does
A regular expression, or regex, is a compact pattern that describes a set of strings. Instead of searching for one fixed word, you describe a shape — “one or more digits”, “an @ between two words”, “a line that starts with a capital letter” — and the engine finds every piece of text that fits. This tester uses your browser’s built-in JavaScript regex engine, so what you see here matches what runs in JavaScript code.
How matches and groups appear
Type a pattern, flip on the flags you need, and paste your text. Each result shows the full match, its zero-based index into the string, and any capture groups. Capture groups are the parts wrapped in parentheses: match[0] is always the whole match, and match[1], match[2], and so on are the groups in the order their opening parentheses appear. When the global flag is off you get only the first match; turn it on to list them all.
- 1 Enter your pattern. Type the regex without slashes, for example (\w+)@(\w+)\.(\w+) to match a simple email.
- 2 Choose the flags. Turn on g to find every match, i to ignore case, m for multiline anchors, s so the dot matches newlines.
- 3 Paste the test string. Add the text to search, such as “Contact ada@knidox.com or grace@example.org”.
- 4 Read the matches. Each row shows the full match and its index — here two matches at index 8 and 26.
- 5 Inspect the capture groups. The first match exposes group 1 = ada, group 2 = knidox, group 3 = com, then copy the list if you need it.
Common tokens and flags
A quick reference for the pieces you will use most; JavaScript regex syntax.
| Token | Matches |
|---|---|
| \d | Any digit, 0–9 |
| \w | A word character: letters, digits, or underscore |
| \s | Any whitespace: space, tab, or newline |
| . | Any character except a newline (unless the s flag is set) |
| * | The preceding item, zero or more times |
| + | The preceding item, one or more times |
| ? | The preceding item, zero or one time (optional) |
| ^ $ | Start and end of the string, or of each line with the m flag |
| [ ] | A character class — any one character listed inside |
| ( ) | A capture group — records the matched text for reuse |
| | | Alternation — match the pattern on either side |
| g i m s | Flags: global, ignore case, multiline anchors, dot matches newlines |
Engines differ, and edge cases matter
Regex syntax is not universal — the JavaScript flavour used here differs in small but real ways from those in Python, PCRE, or grep, so a pattern that works in one may need tweaks in another. Two flags catch people out most often: by default the dot (.) does not match a newline, so use the s flag to let a pattern span lines, and the ^ and $ anchors match the whole string until you add the m flag, which makes them match at each line break instead. When a pattern seems to match “too much”, remember that * and + are greedy by default; add a ? after them (as in .*?) to make them lazy.