Skip to main content
UtilityStack

Regex Tester — JavaScript regular expressions

Build a regular expression and see it match (or fail) against your test string in real time. Capture groups, flags and a replace preview are all live; nothing leaves your browser.

2 match(es)
Pattern
//gi
Replacement
Test string
Replace result
Reach out at <<hello@example.com>> or <<support@utility.test>> for help.
Matches
  • @13hello@example.com
  • @34support@utility.test

What is a regular expression?

A regular expression (regex) is a small language for describing patterns in text. With a few characters you can extract emails from a paragraph, validate that a postcode follows a country's format, or rewrite every snake_case identifier in a file into camelCase. Modern JavaScript engines compile a regex once and then run it as fast as a tight loop.

This tester uses the platform's native RegExp implementation, so anything that works here also works at runtime in Node, Deno, Bun and every modern browser. The flags g, i, m, s, u and y change matching semantics; capture groups (the parentheses in the pattern) collect substrings you can reference in the replacement as $1, $2 etc.

How to use this tool

  1. Either pick a preset (email, URL, IPv4…) or type your own pattern in the regex input.
  2. Toggle the flag buttons (g, i, m, s, u, y) to fine-tune matching. Hover for a description of each flag.
  3. Edit the test string on the right — matches highlight live. The match list below shows position, full match and capture groups.
  4. Add a replacement string to preview a global replace. Use $1, $2, $&, $` and $' the same way String.prototype.replace does.

Frequently asked questions

Which regex flavour is supported?

JavaScript / ECMAScript regex (the same engine your code will run against). That means lookbehinds, named groups (?<name>…) and Unicode property escapes \p{…} all work. PCRE-only features like recursive patterns are not supported.

How do I match a literal special character like . or ?

Escape it with a backslash: \., \?, \(, \). Inside a character class [.] the dot is already literal so [.?] matches a literal dot or question mark.

What's the difference between greedy and lazy quantifiers?

.* is greedy — it grabs as much as possible then backtracks. .*? is lazy — it grabs as little as possible then expands. Lazy is what you want for matching content between markers; greedy is what you want for matching whole lines.

Why does my pattern match nothing the second time?

If you use the global (g) flag and reuse the same RegExp object, lastIndex advances after each exec(). Reset it with regex.lastIndex = 0, or build a new RegExp on each call. This tester resets it for you between renders.

Are my regex and test string sent to a server?

No. Everything runs in your browser via the native RegExp engine. Your inputs never touch our servers, so the tester is safe to use even with sensitive data like a log line containing tokens.

Common use cases

Where reaching for a regex pays off in seconds.

Validate user input

An email, a postcode, a phone number — a tight regex is faster to write than a parser and is fine when you just need a sanity check before sending data downstream.

Extract data from logs

Pull request IDs, IPs or status codes out of a stream of log lines without parsing JSON. Capture groups give you the fields directly.

Rewrite code at scale

Rename a function, change a quote style, or update a deprecated API call across a whole codebase by piping ripgrep into sed — both speak regex.

Find and replace in editors

Most editors (VS Code, JetBrains, Vim) ship a regex search-and-replace. Test the pattern here first to avoid mass-corrupting a file.

Tips and shortcuts

Habits that keep regexes maintainable.

Anchor when you can

If a value should occupy a whole field, anchor with ^ at the start and $ at the end. Without anchors, /\d+/ matches inside 'abc123def' too — usually not what you want for validation.

Prefer character classes over alternation

[abc] is faster and clearer than (a|b|c). Use alternation only when the alternatives are multi-character.

Comment with the x flag if available

JavaScript does not have the verbose flag, but you can build the pattern from a string literal split across lines and join it. For complex patterns, that is a far better readability win than one mega-line.

When regex is the wrong tool

Don't try to parse HTML, JSON or anything with nested structure. Use a real parser (DOMParser, JSON.parse, an AST). Regex shines on flat textual patterns, not tree-structured data.

Related tools