Skip to content
K Knidox Search…
Computer Science · Text

Regex Tester

Test a JavaScript regular expression against your text and see every match and capture group live.

Example patterns — tap to try
Flags /g
56 chars
2 matches
  1. #1 ada@knidox.comindex 8
    • group 1: ada
    • group 2: knidox
    • group 3: com
  2. #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. 1
    Enter your pattern. Type the regex without slashes, for example (\w+)@(\w+)\.(\w+) to match a simple email.
  2. 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. 3
    Paste the test string. Add the text to search, such as “Contact ada@knidox.com or grace@example.org”.
  4. 4
    Read the matches. Each row shows the full match and its index — here two matches at index 8 and 26.
  5. 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.

TokenMatches
\dAny digit, 0–9
\wA word character: letters, digits, or underscore
\sAny 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 sFlags: 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.

Which flags does this tester support?
It supports the JavaScript flags g (global — find every match), i (ignore case), m (multiline anchors), s (dotall — the dot matches newlines), and u (unicode). Toggle any combination; the active flags show after the slash.
What are capture groups?
Capture groups are the parts of a pattern wrapped in parentheses. Each one records the text it matched: match[0] is the whole match, and match[1], match[2]… are the groups in the order their opening parentheses appear. This tester lists them under every match.
Why is my regex not matching newlines?
By default the dot (.) matches any character except a line break, so a pattern like .+ stops at the end of a line. Turn on the s flag (dotall) to let the dot match newlines too, so the pattern can span multiple lines.
Why do ^ and $ not match at each line?
Without the m flag, ^ and $ anchor only to the very start and end of the whole string. Turn on the m (multiline) flag and they anchor at the start and end of every line instead, which is what you usually want for line-by-line matching.
Why do I only see one match?
The global flag is off. Without g, the engine returns just the first match. Turn on g and the tester scans the whole string and lists every match it finds.
How does it avoid getting stuck on empty matches?
A pattern like a* can match an empty string, which would normally leave the scan in place forever. When a match is empty the tester advances the search position by one character, so the loop always moves forward and finishes.