Skip to main content
Calnex LogoCalnex
Developer Tools

Regex Tester

Test a JavaScript regular expression against sample text and list every match with its index and capture groups.

Parameters

Results

Regex Status
VALID ✓
Other results (5)
Match Found
YES ✓
Match Count2
All Matches
1. "Hello World, hello regex!" (at index 0)
2. "" (at index 25)
Matched TextsHello World, hello regex!,
Escaped Pattern (for literal match)
\.\*

Example input and result

/\d+/g
Order 42, item 7
42, 7

Test a JavaScript pattern against a short, representative sample before applying it to a log or validation rule. Enter the pattern body without slash delimiters. Compare match count, captured text and position: a successful substring match does not establish that the whole input is valid. Results stop at 100 matches.

What happens if I omit the g flag?

A non-empty flags value without g, such as i, returns only the first match. A blank Flags field falls back to g in this implementation, so clearing it does not disable global search. Use gi to collect all case-insensitive occurrences.

Why is my match count capped or a zero-length match shown?

When g is set, collection stops after 100 matches, so longer inputs report at most 100. Without g at most one match is collected. With g set, patterns that can match an empty string, such as .* or a*, produce zero-length matches; the engine advances lastIndex by one to avoid an infinite loop, which can place an empty match at the end of the string.

Anchor a validation rule; inspect captures for extraction

The pattern \d+ finds 42 inside ref42x. The pattern ^\d+$ rejects that same string because the anchors require the entire input to consist of digits. For extracting an order number, Order (\d+) includes Order 42 as the whole match and 42 as group 1. Neither pattern is a general-purpose identifier policy.

Frequently asked questions

Does the tool add delimiters around my pattern?

No. Enter the pattern body only, such as \bword\b, and put letters like g or i in Flags. Delimiters such as /.../ are not parsed and would be treated as literal characters.

What does the Escaped Pattern output do?

It backslash-escapes the characters . * + ? ^ $ { } ( ) | [ ] and \ so the result can be reused as a literal string. Other characters are left unchanged. It is a convenience string, not a validated expression.

Which regex syntax is supported?

Whatever the browser's JavaScript RegExp constructor accepts, including groups, lookarounds and the u flag. An unsupported construct makes Regex Status show INVALID and an Error message instead of matches.

Four searches with different matching rules (4)

How do I count numbers in a sentence with a global pattern?

Regex Pattern
\d+
Test String
Order 42 and 7
Flags
g
  1. Set Regex Pattern to \d+, Test String to Order 42 and 7, and Flags to g.
  2. \d+ matches one or more digits; scanning finds 42 at index 6 and 7 at index 13, giving Match Count 2 and Matched Texts 42, 7.
Match Count
2
Matched Texts
42, 7

Each run of digits is one match; decimals or signs would need a different pattern. The 100-match cap applies to longer text.

How do I find a word regardless of letter case?

Regex Pattern
hello
Test String
Hello World, hello regex!
Flags
gi
  1. Set Regex Pattern to hello, Test String to Hello World, hello regex!, and Flags to gi.
  2. The i flag makes matching case-insensitive and g collects all hits, so Hello at index 0 and hello at index 13 both match: Match Count 2, Matched Texts Hello, hello.
Match Count
2
Matched Texts
Hello, hello

Matched Texts keeps the original casing from the input, not the pattern. Without i only the lowercase occurrence would match.

Reject digits surrounded by other characters

Regex Pattern
^\d+$
Test String
ref42x
Flags
g
  1. Set the pattern to ^\d+$ and test ref42x with g.
  2. No match is returned, whereas \d+ alone would find 42.
Match Count
0
Match Found
NO ✗

Anchoring changes the question from finding a substring to checking a whole input.

Return only the first case-insensitive occurrence

Regex Pattern
hello
Test String
Hello hello HELLO
Flags
i
  1. Use hello with the non-empty flag i on Hello hello HELLO.
  2. Only Hello is returned; use gi to collect all three occurrences.
Match Count
1
Matched Texts
Hello

A blank Flags field currently falls back to g. Use i for this first-match example.