Logo

Regex Tester

Test regular expressions with instant visual feedback

Regular Expression

//g

Common Patterns

Sample Texts

0 Matches Found

Test Text

Highlighted Matches

No matches to display

Free Online Regex Tester — Test Regular Expressions Instantly

Regular expressions are one of the most powerful tools in a developer's toolkit. They let you search, match, and manipulate text using patterns. But writing the right regex can be tricky — a single misplaced character can change the entire behaviour. That is where a live regex tester becomes essential. Instead of running your code, deploying, and checking logs, you can test your pattern right here and see every match highlighted instantly.

This free Regex Tester supports all six JavaScript regex flags: global (g), case-insensitive (i), multiline (m), dotAll (s), unicode (u), and sticky (y). Type your pattern, paste your test string, and watch matches appear in real time. Every match is colour-coded and numbered. Capture groups are shown separately. You can also use the built-in replace mode to test find-and-replace operations.

Eight common patterns are built in — email, URL, phone number, hex colour, IP address, date, HTML tag, and plain numbers. Four sample texts are provided so you can test patterns instantly. All processing runs in your browser. No data is sent to any server.

Understanding Regex Flags

g — Global

Find all matches in the string, not just the first one. Without this flag, the regex stops after the first match.

i — Case-insensitive

Treat uppercase and lowercase letters as the same. "abc" matches "ABC", "Abc", and so on.

m — Multiline

Make ^ and $ match the start and end of each line, not just the start and end of the entire string.

s — DotAll

Make the dot (.) match newline characters as well. By default, dot matches everything except newlines.

u — Unicode

Enable full Unicode support. Required for matching emoji, CJK characters, and other multi-byte sequences correctly.

y — Sticky

Match only from the position indicated by lastIndex. Useful for tokenisation and lexer implementations.

Common Regex Patterns Explained

Email validation

[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} — Matches standard email addresses with alphanumeric local parts and domain names.

URL matching

https?://[\w\-]+(\.[\w\-]+)+[/#?]?.* — Matches HTTP and HTTPS URLs with domain names, paths, and query strings.

Phone numbers

\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4} — Matches US phone numbers in various formats: (123) 456-7890, 123-456-7890, 123.456.7890.

IP addresses

\b(?:\d{1,3}\.){3}\d{1,3}\b — Matches IPv4 addresses like 192.168.1.1. Does not validate range (0-255).

Dates

\d{4}-\d{2}-\d{2} — Matches dates in YYYY-MM-DD format. Does not validate month or day ranges.

HTML tags

<[^>]+> — Matches opening and closing HTML tags including self-closing tags. Not suitable for full HTML parsing.

Frequently Asked Questions

Is this regex tester free?+
Yes, completely free with no account, no ads, and no limits on usage.
Is my data sent to a server?+
No. All regex testing runs locally in your browser. Nothing is uploaded.
What regex engine does it use?+
JavaScript's built-in RegExp engine. All results match what you would get in Node.js or any browser.
Does it support capture groups?+
Yes. Capture groups are shown separately for each match with their index numbers.
Can I do find and replace?+
Yes. Toggle the Replace button to enter a replacement string. The result updates in real time.
What are the highlight colours?+
Five rotating colours are used to distinguish adjacent matches: amber, violet, pink, teal, and blue.
Can I copy the regex?+
Yes. Click "Copy Regex" to copy the pattern with flags in /pattern/flags format.
Does it work on mobile?+
Yes. The layout is fully responsive with a sidebar on desktop and stacked on mobile.

Why greedy matching swallows more than you meant

The single most common regex surprise, and it is a design decision rather than a quirk.

Quantifiers are greedy by default. `*` and `+` consume as many characters as possible while still permitting an overall match, then give characters back only as needed. So `<.*>` applied to "<a><b>" matches the entire string: the dot-star takes everything, backs off to find a final ">", and stops at the last one.

Making the quantifier lazy with a question mark reverses the preference. `<.*?>` takes as little as possible, so it matches "<a>" and then "<b>" separately.

The better habit is often to avoid the dot entirely. `<[^>]*>` says "anything that is not a closing bracket", which expresses the intent directly and cannot overrun. Being specific about what you will accept beats adjusting greediness after the fact.

Reading capture groups instead of guessing

A pattern that matches is only half the answer. What it captured is usually the part you need.

Parentheses create a capture group, numbered left to right by opening bracket. Nested groups make this fiddly to count by hand, which is exactly why inspecting them in a tester is faster than reasoning about them.

Two things catch people. A non-capturing group, written `(?:...)`, groups for the purposes of a quantifier without capturing — so it does not take a number, and every subsequent group shifts. And a group inside an optional section can match overall while that group participated in nothing, giving you an empty or undefined capture.

Named groups help considerably on anything non-trivial. Referring to a value by name rather than position survives you adding a group in the middle six months later.

The backtracking failure that hangs a server

This is the regex problem with genuine production consequences, and it is invisible in small tests.

A backtracking engine explores possibilities. With nested quantifiers, the number of possibilities can grow exponentially with input length. A pattern like `(a+)+b` against thirty "a" characters and no "b" forces the engine through an astronomical number of combinations before concluding there is no match.

On your ten-character test it returns instantly. On a real input it pins a CPU core indefinitely. Where the pattern runs on user-supplied input, that is a denial-of-service route — someone sends a crafted string and your request handler stops responding.

The defences are structural. Do not quantify a group that already contains a quantifier. Replace the dot with a specific character class so alternatives cannot overlap. Anchor the pattern so the engine cannot retry at every position. And test with input far longer than your examples, because length is what exposes it.

When a regular expression is the wrong tool

Knowing where to stop is worth more than any pattern trick.

Nested structures are the hard limit. HTML, XML, JSON and programming languages all nest to arbitrary depth, and regular expressions cannot express arbitrary nesting — it is a property of what they are, not a gap in any implementation. A pattern will work on your examples and fail on real input, which is the worst kind of failure because it passes review.

Email addresses are the famous near-miss. The specification permits quoted strings, comments and address literals, and a pattern that genuinely matches it is pages long and unmaintainable. Check for an at sign with plausible content either side, then send a confirmation message. Delivery is the only validation that means anything.

Where a regex does excel: finding a known pattern in flat text, splitting on a delimiter, validating a format you control such as a product code, and search-and-replace across a codebase. Those are the jobs it was built for, and it does them better than anything else.

How to use the Regex Tester

  1. Enter your pattern and paste sample text that includes the awkward cases.
  2. Set the flags deliberately — global for every match, multiline for per-line anchors.
  3. Check the capture groups, not just whether the whole pattern matched.
  4. Make quantifiers lazy with a question mark if a match is swallowing too much.
  5. Test against input much longer than your examples to expose backtracking.

What this tool handles

Live match highlighting

See exactly which characters matched rather than inferring from a yes or no.

Capture group inspection

Every group listed with what it captured, including the ones that came back empty.

Flag control

Global, multiline, case-insensitive and dotAll, each changing behaviour independently.

Runs in your browser

No request is made, so sample data stays on your machine.

Frequently asked questions

Why does my pattern match more than I expected?

▼
Greedy quantifiers. By default `*` and `+` take as much as they can while still allowing a match, so `<.*>` on "<a><b>" matches the whole string rather than "<a>". Adding a question mark makes them lazy: `<.*?>` matches each tag separately.

What is catastrophic backtracking?

▼
A pattern whose match time grows exponentially with input length, so it appears to hang. Nested quantifiers are the usual cause — something like `(a+)+b` against a long run of "a" characters. The engine tries an enormous number of combinations before giving up.

How do I avoid writing one?

▼
Avoid nesting a quantifier inside another quantified group. Prefer specific character classes over the dot. Anchor your pattern where you can. And test against input longer than your examples — the problem only shows at scale.

Does a regex that works here work in Python?

▼
Usually, but not always. This tests against the JavaScript engine, and flavours differ in lookbehind support, named group syntax, and how they handle Unicode. Simple patterns are portable; anything using advanced features needs testing in its target language.

Why does my capture group come back empty?

▼
Commonly because it is inside an optional group that did not participate in the match, or because you used a non-capturing group `(?:...)` by mistake. The match inspector shows which groups filled, which is faster than reasoning about it.

What is the difference between the global and multiline flags?

▼
Global finds every match rather than stopping at the first. Multiline changes what `^` and `$` mean, so they match at each line break instead of only at the start and end of the whole string. They are frequently confused and do unrelated things.

Should I use a regex to parse HTML?

▼
No. HTML nests arbitrarily and regular expressions cannot express arbitrary nesting, so any pattern works on your examples and fails on real documents. Use a parser. The same applies to JSON and to most programming languages.

Is a regex the right way to validate an email address?

▼
Only loosely. The full specification is extraordinarily permissive and a pattern matching it correctly is unreadable. Check for an at sign with something plausible either side, then send a confirmation email — delivery is the only real validation.

Is my pattern or test text sent anywhere?

▼
No. Matching runs in your browser using its own regex engine, with no network request. That matters if your test data is a sample of real records.

Why does the dot not match my line breaks?

▼
Because by default the dot matches any character except a newline. The dotAll flag changes that. This catches people out constantly when a pattern works on one line and fails across two.

Related Tools You Might Like

Advertisement