Regex Tester

Use this regex tester to build and check regular expressions against sample text, with every match highlighted and its capture groups and position listed.

1Type your pattern and set the flags
2Paste or type the test text
3Read the highlighted matches and group details

Private by design: 100% in your browser — nothing is uploaded, no sign-up. This tool runs entirely on your device.

How to use this regex tester

Type a pattern, tick the flags you need, and the matches in your test text light up as you type — no button to press. Under the highlighted text, every match is listed with its exact starting position and the value of each capture group, which is the information you actually need when a pattern is almost right. A pattern with a syntax error reports the browser's own error message, so you can see precisely which character the engine objected to. The sample button loads an email-finding pattern with decoys — addresses that look close but must not match — so you can see the tester separate real matches from near misses.

Work the way experienced developers do: start with a test string where you already know the answer, get the simplest version of the pattern matching, then add one requirement at a time — an anchor, a boundary, a group — re-checking after each step. Most “regex is impossible” moments are really “five requirements were added at once and one of them is wrong”, and the position numbers in the match list tell you which one.

Example: finding the numbers in a sentence

The pattern \d+ — one or more digits — with the global flag on, run against the text loaded when this page opens:

Order 4521 ships on 12 March and arrives within 5 days. Tracking code: X9-2044.

finds five matches: 4521 at position 6, 12 at position 20, 5 at position 48, and the tracking code contributes two matches of its own — 9 and 2044 — because the hyphen is not a digit and splits them. That last detail is the classic regex lesson: the engine finds exactly what the pattern describes, not what you meant, and seeing the matches highlighted is how you catch the difference.

A short survival guide to regex syntax

The 20% of syntax that does 80% of the work: . any character; \d \w \s a digit, a word character, whitespace (capitals negate them); [a-z] any character in a set; * + ? zero-or-more, one-or-more, optional; {2,4} a counted repeat; ^ $ start and end (of the text, or of each line with the m flag); \b a word boundary; (…) a capture group; | alternation. Escape a character with a backslash when you mean it literally — a real dot is \. — and remember that inside a web page or a JSON string the backslashes themselves may need doubling. When a pattern misbehaves, the cause is almost always one of three things: a missing escape, a greedy quantifier eating too much, or an anchor quietly meaning “start of everything” when you meant “start of line”.

Patterns worth keeping

A few patterns cover a large share of everyday validation and extraction. Each is a starting point, not gospel — test them here against your own awkward cases before trusting them:

JobPatternWatch out for
ISO date\d{4}-\d{2}-\d{2}Matches 2026-99-99 too — a pattern checks shape, not the calendar
Hex colour#(?:[0-9a-fA-F]{3}){1,2}\bAdd {4} variants if you need alpha channels (#RRGGBBAA)
Simple email[\w.+-]+@[\w-]+\.[\w.]+Real email syntax is far stranger; perfect validation means sending a message
URL slug^[a-z0-9]+(?:-[a-z0-9]+)*$Lowercase first, or add the i flag deliberately
IPv4 address\b(?:\d{1,3}\.){3}\d{1,3}\bAccepts 999.1.1.1 — range-check the numbers in code if it matters
Whole word\bcat\bThe \b boundaries stop it matching inside “catalogue”

The shared lesson of the right-hand column is the most important one on this page: a regex validates the shape of text, not its truth. Dates must exist, octets must be under 256, emails must receive — the pattern is the first filter, never the whole check.

Frequently asked questions

What is a regular expression?

A regular expression (regex) is a pattern language for finding text: letters match themselves, and symbols add powers — \d means any digit, + means 'one or more', ^ and $ anchor to the start and end. Developers use regexes to validate input, search logs and extract pieces of text.

What do the flags mean?

g (global) finds every match instead of stopping at the first. i makes matching case-insensitive. m makes ^ and $ match at line boundaries, not just the ends of the whole text. s lets . match newline characters too. u enables full Unicode behaviour. y (sticky) requires each match to begin exactly where the previous one ended.

What is a capture group?

Parentheses in a pattern capture the part of the match they enclose, so you can extract it separately — in (\w+)@(\w+), group 1 is the part before the @ and group 2 the part after. This tool lists every group for every match. Use (?:…) when you need grouping without capturing.

Why does my pattern match nothing?

The usual causes: special characters that need escaping (a literal dot is \.), anchors ^ and $ behaving differently without the m flag, or a greedy quantifier behaving as designed. Try the pattern against a tiny test string where you know the answer, and build it up piece by piece.

Why does the tester stop at 1,000 matches?

Patterns like a* can match at every position of a long text, producing tens of thousands of empty or trivial matches and freezing the page. The tester caps results at 1,000 matches and lists the first 100, which is more than enough to confirm a pattern behaves as intended.

What is the difference between .* and .*?

Quantifiers are greedy by default: .* takes as much text as possible while still allowing an overall match. Adding ? makes it lazy — .*? takes as little as possible. On the text 'a b c', the pattern a.*c matches the whole string, while a.*?c stops at the first c it can.

Is my test text uploaded anywhere?

No. Matching runs with JavaScript's RegExp engine inside your browser. You can safely test patterns against log excerpts, configuration files or sample data that you would not paste into a server-side tool.

Will a pattern that works here work in my programming language?

Mostly — this tester uses JavaScript's regex dialect, which shares its core syntax with Python, Java, PHP and others. Dialects differ in advanced corners: lookbehind support, named-group syntax and some character-class shortcuts vary, so treat a passing test here as strong evidence, then confirm in your target language.

What is catastrophic backtracking?

Some patterns — classically nested quantifiers like (a+)+$ — make the engine try an exploding number of combinations on text that almost matches, which can hang a program. If a pattern feels slow here on a short string, that is the warning sign: simplify it before using it in production code.

Related tools