Regex Tester

Test JavaScript regular expressions, flags, captures, and match positions locally.

  • Free
  • No signup
  • Runs in your browser

Results are capped at 1,000 matches. Native JavaScript regex execution cannot guarantee protection from every pathological pattern.

How it works

How to use

Enter a JavaScript pattern, flags, and test text, then run the test.

Method

Native RegExp matching reports bounded match, capture, and position data.

Example

Use the g flag to inspect every match, up to 1,000.

A regex result comes from three moving parts

A pattern by itself does not determine what this tester will show. SnakTool sends the pattern, selected flags and test text to the browser's JavaScript RegExp engine, then reports what that execution returns.

That engine choice matters. A pattern copied from PCRE, Python, Java, .NET or another regex dialect can use syntax or semantics that JavaScript does not share. Enter the pattern itself here rather than JavaScript-style surrounding slash delimiters.

Execution model
pattern + flags + test text
          ↓
 JavaScript RegExp
          ↓
match text + index + captures + named groups

Turn on g and the question changes from where to how many

Without the global flag, SnakTool executes the expression for its first match and stops. That is why a pattern can clearly occur several times in the test text while the result panel contains only one match.

With g enabled, the tester repeatedly executes the expression and collects successive matches until the search finishes or the result cap is reached. The pattern itself can remain identical while the number of reported results changes.

Same pattern, different execution
Text:    cat dog cat fox cat
Pattern: cat

No g → cat @ 0
With g → cat @ 0, cat @ 8, cat @ 16

Open a match and inspect what the engine actually captured

The full matched text is only the outer layer of a result. SnakTool also exposes the match index, numbered captures created by capturing parentheses, and named groups when the expression defines them.

This makes grouping mistakes visible. Parentheses such as (foo) create a capture, while a non-capturing group such as (?:foo) groups part of the expression without adding a numbered capture. An optional capturing group can also be unmatched rather than containing an empty value.

Match anatomy
Pattern: (\w+)@(?<domain>[\w.-]+)
Text:    [email protected]

Full match → [email protected]
Index      → 0
Capture 1  → sara
domain     → example.com

Change one flag at a time when the match surprises you

Flags change execution rules, so debugging is easier when you alter one condition and observe the result. The i flag changes case sensitivity; m changes how ^ and $ recognize line boundaries; and s lets the dot metacharacter match line terminators.

These flags are not interchangeable fixes. If ^error fails to find error at the start of a later line, m is relevant. If start.*end must cross a newline, s addresses a different rule. If Cat should match cat, i changes case comparison.

FlagUseful question to test
gDo I need every match or only the first?
iShould case differences matter?
mShould ^ and $ recognize line boundaries?
sShould . be able to cross a line terminator?
uShould the pattern use Unicode-aware JavaScript semantics?
vDoes this runtime support the Unicode Sets behavior the pattern needs?
yMust the next match begin exactly at the current search position?

Global and sticky both use position, but they search differently

JavaScript's g and y flags both make RegExp execution stateful through lastIndex, but they do not mean the same thing. A global expression can search forward from its current position for the next match, while a sticky expression requires a match to begin exactly at its current lastIndex.

Sticky matching is therefore useful in parser or tokenizer-style workflows where skipping unexpected text would be wrong. SnakTool passes y directly to the browser's RegExp engine, so its behavior follows that JavaScript execution model.

A pattern can compile correctly and still answer the wrong question

There is an important difference between a syntax error and a valid expression that finds nothing—or finds too much. SnakTool constructs a JavaScript RegExp from your pattern and flags; malformed regex syntax is rejected by the engine rather than treated as a successful no-match result.

A valid pattern such as \d+ searches for a run of digits somewhere in the text. It does not mean the entire input consists only of digits. For whole-string validation, boundaries such as ^ and $ may be part of the intended expression, subject to the flags and semantics your application requires.

Search versus whole-string condition
Text: abc123xyz
\d+     → matches 123
^\d+$   → does not match the whole text

When a match swallows too much, inspect greediness before adding more syntax

Quantifiers such as * and + are greedy by default: they try to consume as much as they can while still allowing the expression to succeed. This is why a pattern intended for one quoted value can unexpectedly span across several quoted values.

Lazy quantifiers such as *? and +? change that preference. Comparing the greedy and lazy forms on a small sample is often more informative than making a large production pattern increasingly complicated.

Greedy versus lazy
Text: "a" and "b"
".*"  → "a" and "b"
".*?" → first short quoted match; add g to collect later ones

An empty match still occupies an execution position

Some valid expressions can succeed without consuming any text. In repeated matching, returning the same zero-length result at the same position forever would make a naive loop stall.

SnakTool detects an empty global match and advances lastIndex by one before continuing. That safeguard is about progressing through zero-length results; it does not change the regex syntax or turn an empty match into a one-character match.

The displayed index is a JavaScript string index

Match positions come from JavaScript RegExp and are measured in UTF-16 code units, not necessarily in visible characters or Unicode code points. For plain ASCII those counts usually look identical.

The difference becomes visible with characters represented by surrogate pairs. In the text 😀a, the emoji occupies two UTF-16 code units, so the match index for a can be 2 even though a appears to be the second visible character.

UTF-16 position example
Text: 😀a
Visual position of a → second character
JavaScript index of a → 2

One thousand results is a display boundary, not an execution timeout

With global matching, SnakTool collects at most 1,000 matches and reports when results were truncated. That prevents an enormous successful match set from growing without bound.

It does not limit how much work the JavaScript regex engine can perform while trying to decide whether a match exists. A pathological backtracking expression can spend substantial time inside a single RegExp execution before the 1,000-result cap has any opportunity to help.

Two different runaway problems
Many successful matches
        ↓
1,000-result collection cap

Expensive backtracking
        ↓
work can happen before a result exists

Test hostile or unfamiliar patterns as code with a performance cost

Nested or ambiguous quantifiers can create catastrophic backtracking on certain inputs in backtracking regex engines. This tester does not provide a separate regex execution timeout, so the match-count cap should not be treated as ReDoS protection.

Keep experimental inputs small when testing unfamiliar patterns, and review production expressions in the environment that will actually execute them. A browser test can demonstrate JavaScript behavior, but it cannot guarantee portability, performance or safety in a different regex engine.

Frequently asked questions about Regex Tester

Are match positions always visible-character counts?

No. JavaScript RegExp indexes use UTF-16 code units. Characters represented by surrogate pairs can occupy two code units, so a displayed match index can differ from a simple count of visible characters.

Does the 1,000-match limit prevent catastrophic backtracking?

No. The cap limits how many successful matches SnakTool collects. Expensive backtracking can happen while the JavaScript engine is still trying to produce a result, and this tester does not impose a separate regex execution timeout.

What regex engine does SnakTool use?

It uses the JavaScript RegExp implementation provided by the browser. Patterns should therefore be interpreted according to JavaScript regex syntax and runtime support.

Do I include slash characters around the regex pattern?

No. Enter the pattern itself rather than JavaScript literal delimiters such as /pattern/g. Flags are supplied separately.

Why do I only get one regex match?

Check whether g is enabled. Without the global flag, this tester intentionally executes for the first match only.

What does the s flag do?

s is dotAll mode. It allows the dot metacharacter to match line terminators, which matters for patterns intended to span line breaks.

What does the y sticky flag do?

A sticky expression requires its next match to begin exactly at the current lastIndex rather than searching farther ahead for a match. This can be useful in tokenizer-style parsing.

What is a regex capture group?

Capturing parentheses store the substring matched by that group in addition to the full match. SnakTool reports those numbered captures with each match.

What does the regex match index mean?

It is the JavaScript string index where the full match begins. The index is measured in UTF-16 code units.

How do I require the whole string to match?

A common JavaScript approach is to anchor the intended pattern with ^ at the start and $ at the end, while considering how flags such as m change anchor behavior.

What is lazy regex matching?

Adding ? to a quantifier such as *? or +? changes its preference toward shorter consumption while still allowing the expression to succeed.

How many regex matches can SnakTool return?

Global matching collects at most 1,000 matches. When that cap is reached, the result is marked as truncated.

Can a regex freeze or slow the browser?

A pathological JavaScript RegExp can consume substantial execution time, especially with backtracking-heavy patterns. Keep unfamiliar patterns and test text small.

Does a regex match prove an email or URL is real?

No. A regex can test whether text matches the pattern you wrote. It does not prove that an email mailbox exists, a URL is reachable, or external data is authentic.

Browse all Developer Tools