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:
g— global: find all matches, not just the first.i— case-insensitive.m— multiline:^and$match the start/end of each line.s— dotall:.also matches newlines.
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.