Toolsky

Free Online Tools & Utilities for Every Task.

Regex Tester

Test your regular expressions in real-time with syntax highlighting and a cheatsheet.

/
/
Results
No matches found.

Try adjusting your regex pattern or test string.

Regex Cheatsheet
.Any character except newline
\wWord (A-Z, a-z, 0-9, _)
\dDigit (0-9)
\sWhitespace (space, tab, etc)
[abc]Any of a, b, or c
[^abc]Not a, b, or c
*0 or more
+1 or more
?0 or 1
{3}Exactly 3
{3,}3 or more
{3,5}Between 3 and 5
^Start of string / line
$End of string / line
\bWord boundary
(abc)Capture group
(?:abc)Non-capturing group
(?=abc)Positive lookahead
(?!abc)Negative lookahead
gGlobal match
iCase-insensitive
mMulti-line
uUnicode
sDot matches newline

Regular expressions are famously write-once, debug-forever. A pattern that looks right in your head matches the wrong half of the string, or matches nothing at all, and the difference between the two outcomes is usually one character class. A regex tester closes that feedback loop: you write a pattern, paste in sample text, and see the matches light up as you type — with syntax highlighting to show how the pattern itself is being read, and a built-in cheatsheet for the symbols you half-remember. It turns pattern-writing from guesswork into something closer to aiming.

What This Regex Tester Does

The tester evaluates your expression against your test text in real time, highlighting every match and the capture groups inside it. That immediacy is the point. Regex failure is rarely dramatic — it is a date pattern that also swallows times, an email pattern that accepts "a@b" as an address — and small wrongness is only visible when you watch the matches change keystroke by keystroke. The cheatsheet sits alongside so that checking whether \w includes underscores (it does) or whether . matches newlines (it does not, by default) costs a glance instead of a search-engine detour. MDN's regular expressions guide remains the full reference when the cheatsheet runs out.

Built-In Help While You Test

  • Live match highlighting — matches update as you edit the pattern or the sample text, so cause and effect stay connected.
  • Syntax highlighting of the pattern — groups, classes and escapes are coloured differently, making unbalanced brackets and stray characters visible.
  • Capture group visibility — see what each parenthesised group actually captured, not just that something matched.
  • Flags within reach — global, case-insensitive and multiline behaviour change results completely; testing with the flags you will ship is essential.
  • The cheatsheet — anchors, quantifiers, character classes and escapes summarised where you are already working.

How to Test a Pattern

  1. Write or paste your regular expression into the pattern field.
  2. Paste representative sample text — and include lines that should not match, or you are only testing half the pattern.
  3. Set the flags your real code will use.
  4. Read the highlighted matches: check where each match starts and ends, not merely that one exists.
  5. Inspect the capture groups if your code depends on extracting pieces.
  6. Refine the pattern, then throw edge cases at it — empty lines, maximum lengths, lookalike strings.
  7. Copy the proven pattern into your project, with your test strings saved as real tests if the code matters.

A Worked Example: Pulling Dates Out of a Log

Suppose a server log mixes dates into prose and you want every date in ISO form. Start loose: \d{4}-\d{2}-\d{2} against the sample "Deployed 2026-10-28 at 09:41; rollback target 2026-1-5 failed; backup id 8842-10-99 archived". The tester shows two matches — 2026-10-28 and the nonsense 8842-10-99 — and one miss, because 2026-1-5 has single digits the {2} quantifiers reject. That visibility drives the fix: tighten to \b\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])\b, and now the backup ID fails its month check while real dates match. One trap survives, and honest testing reveals it: 2026-02-31 sails through, because regex validates shape, not calendars. Date logic belongs in code afterwards; the pattern's job is extraction. This test-driven rhythm is the same one you would use building a validation pattern before handing it to an email validator comparison, or a find-pattern destined for a text replacer.

Regex Traps Even Experienced Users Hit

The classics, in rough order of body count. Greediness: .+ between two delimiters matches to the last delimiter on the line, not the first — the lazy .+? exists for a reason. Unescaped dots: writing example.com in a pattern makes the dot a wildcard, so it happily matches exampleXcom. Anchoring: a pattern that validates input needs ^ and $ around it, or it "validates" any string containing a valid substring. Catastrophic backtracking: nested quantifiers like (a+)+ against a long non-matching string can hang an engine — if the tester freezes, your pattern, not the tool, is the bug. And flavour drift: syntax differs subtly between JavaScript, PCRE and Python engines, so test in the flavour you will deploy, and keep patterns as simple as the job allows — a pattern nobody on the team can read is a liability regardless of correctness.

Frequently Asked Questions About Testing Regular Expressions

Why does my pattern match things it should not?

Almost always one of three causes: an unescaped dot acting as a wildcard, a missing anchor letting the pattern match a substring, or a character class wider than you pictured. Watch the highlight boundaries while you narrow each suspect.

What do the flags g, i and m actually do?

g finds every match instead of stopping at the first; i makes matching case-insensitive; m lets ^ and $ anchor at line boundaries instead of only the whole string. The same pattern can return completely different results under different flags.

How do I test that a string does NOT match?

Include deliberate near-misses in your sample text — strings that share most of the shape but break one rule — and confirm they stay unhighlighted. A pattern is only trustworthy when its failures are as well-tested as its successes.

Why does my pattern work here but fail in my code?

Flavour and escaping differences. In many languages the pattern sits inside a string, where backslashes need doubling, and engines differ on features like lookbehind support. Note which engine your project uses and mirror its rules when testing.

What is the difference between .* and .*?

The first is greedy: it consumes as much as possible, then gives characters back only until the rest of the pattern can match. The second is lazy: it consumes as little as possible. Greediness is the single most common reason extractions grab too much text.

Can a regular expression validate email addresses completely?

Not to the full RFC standard — the complete grammar is famously impractical as a single pattern. Sensible patterns check the broad shape (something, @, something, a dot, something), and real validation is completed by sending a confirmation message.

How do I extract only part of each match?

Wrap the part you want in parentheses: it becomes a capture group, reported separately from the overall match. The tester shows group contents so you can confirm each group holds what your code expects.

Patterns You Have Proven, Not Just Written

A regex you have watched succeed and fail against honest test strings is a tool; one you have only stared at is a hope. Keep the sample text adversarial, and the patterns that survive it will survive production too.