Skip to main content

Developer Tools

Regex Tester

Test JavaScript regex patterns and inspect matches and capture groups.

Regex Tester tool

Loading tool…

Jump to a section

About This Tool

Regular expressions are compact pattern descriptions used for searching, validation, parsing, and text transformation. Small syntax changes can alter what a pattern matches, especially once flags, anchors, character classes, quantifiers, and capture groups are involved. This tester runs a pattern against your sample text with the browser's JavaScript RegExp engine and lists the exact matched text, starting index, numbered capture groups, and named capture groups. It is intended for learning and debugging JavaScript-compatible expressions without sending the pattern or test text to a server.

How To Use It

  1. Enter a JavaScript regular expression pattern without surrounding /slashes/.
  2. Add JavaScript flags such as g for repeated matches, i for case-insensitive matching, or m for multiline anchor behavior.
  3. Paste or type representative test text. Results update locally and show each match's starting index and capture groups.
  4. Test realistic edge cases before using a regex in production. A successful sample does not prove a pattern is safe or correct for every possible input.

Examples

Whole words

Pattern \bcat\b with flags gi matches Cat and cat as complete words while avoiding characters embedded inside a longer word.

Named email parts

Pattern (?<user>[a-z]+)@(?<domain>[a-z]+\.[a-z]+) with gi can expose the user and domain portions as named groups for simple controlled examples.

Multiline starts

Pattern ^TODO: with flags gm can find lines that begin with TODO:. The m flag changes how ^ and $ behave across line boundaries.

Useful Notes

JavaScript regex syntax

The tool uses the browser's RegExp implementation, so syntax and supported features follow the JavaScript engine in your browser. Enter the pattern body only; flags have their own field. Features available in another regex flavor such as PCRE, Python, Java, or .NET may differ or be unsupported.

Global and sticky matching

Without g or y, JavaScript RegExp.exec returns the first match only. With g, the tester continues through the text and reports repeated matches. Sticky y matching requires the next match to begin at the engine's current lastIndex, so it behaves differently from a general search.

Capture groups

Parentheses capture portions of a match unless they are non-capturing. Numbered groups appear in order, while (?<name>...) creates a named group when supported. A group can be undefined when its branch did not participate in a particular match.

Flags change semantics

Common flags include g for global matching, i for case-insensitive matching, m for multiline anchors, s for dotAll, and u for Unicode-aware parsing. Modern engines may also support d, v, and y. Duplicate or unsupported flags are rejected rather than silently ignored.

Performance and ReDoS risk

Some regular expressions can require extreme backtracking on specially shaped input. Browser JavaScript does not provide a portable way to interrupt a RegExp that is already executing. This tool limits pattern and input sizes, but those limits cannot guarantee that every pattern completes quickly. Do not paste untrusted pathological patterns or rely on this page as a regex security analyzer.

Validation is more than a regex

Regex can check textual shape, but many real values also need semantic rules. Email addresses, URLs, dates, identifiers, and structured formats can have standards or context that a short pattern does not fully represent. Prefer purpose-built parsers when correctness depends on those rules.

FAQ

Should I include /slashes/ around the pattern?

No. Enter only the pattern body. Put flags such as g or i in the separate Flags field.

Why do I see only one match?

Add the g flag when you want JavaScript to continue searching for additional matches. Without g or y, the tester intentionally reports the first match.

Can a regex freeze the page?

A pathological backtracking expression can take a long time in JavaScript, and a running RegExp cannot be reliably cancelled in all browsers. Input limits reduce exposure but do not eliminate this risk, so avoid untrusted complex patterns.

Is my test text uploaded?

No. Matching is performed by the browser code on this page; the tool does not need an API or backend for the regex operation.