How to test a regular expression

A regex that looks right in your head often behaves differently against real text. The reliable way to build one is to test it live against sample input and watch what it matches. This guide shows how, explains the flags and groups, and covers the mistakes that trip most people up.

The fastest way

Open the Regex Tester, paste in sample text, and type your pattern — matches highlight as you type. Iterate until it matches exactly what you want and nothing you don't.

Flags change everything

The same pattern behaves differently depending on its flags:

Capture groups

Parentheses pull out part of a match. This splits a date into pieces you can reuse:

(\d{4})-(\d{2})-(\d{2})
matches 2026-10-25 → group 1 = 2026, group 2 = 10, group 3 = 25

Use (?:...) when you need grouping but don't want to capture.

Greedy vs. lazy

Quantifiers like * and + are greedy — they grab as much as possible, which is the usual cause of "it matches too much." Add a ? to make them lazy: <.*?> matches a single tag, where <.*> would swallow a whole line.

From matching to replacing

Once a pattern matches what you want, you often want to replace it. For straightforward search-and-replace across a block of text (with regex support), use Find & Replace.

A note on privacy

Test data is often real data. The Regex Tester runs entirely in your browser, so your pattern and sample text are never uploaded to a server.

Open the Regex Tester →

Common questions

What is a regex flag?

Flags change how a pattern is applied. The common ones are g (global — find all matches, not just the first), i (case-insensitive), m (multiline — ^ and $ match line starts/ends), and s (dotall — . also matches newlines). You combine them, e.g. gi.

What is a capture group?

Parentheses create a capture group, which pulls out part of a match for reuse. (\d{4})-(\d{2}) captures a year and month separately. Use (?:...) for a non-capturing group when you need grouping but not extraction.

Why does my regex match too much?

Usually because quantifiers like * and + are greedy — they match as much as possible. Make them lazy with a trailing ? (.*? instead of .*) to match the shortest span, which fixes most over-matching problems.

Is my text uploaded when I test a regex?

No. The pattern runs against your sample text entirely in your browser, so logs, data, and anything you paste never leave your device.