A regex is checked by running it against a sample string and inspecting the matches, capture groups, and named groups it produces — and the fastest way to do that for JavaScript patterns is to type the regex into the Regex Tester field, toggle the flags you need, and read the highlighted matches in the results below as you type.

Checking a regular expression is a build-test-tweak loop, not a one-shot verification. You write a pattern, you test it against representative input, and you adjust until the matches and groups look exactly right. The catch is that different languages use slightly different regex dialects, so a pattern that works in Python may behave differently in JavaScript. The Regex Tester uses the browser's native JavaScript RegExp engine, which means a pattern that matches in the tester will match the same way in JavaScript, TypeScript, and Node — and vice versa. There is nothing to install, nothing to upload, and nothing to sign up for; the tool runs entirely in your browser using local JavaScript, so your pattern and your test text stay on your device.

how to check regex
how to check regex

The Three Jobs a Regex Check Does

To "check a regex" usually means one of three things, and the same tool can answer all of them.

  • Validation: Does this pattern accept valid input and reject invalid input? You test it against a few positive and negative examples to confirm.
  • Extraction: Does this pattern pull out the fields I need — dates, IDs, prices, slugs? You look at the capture groups and named groups to confirm the structure.
  • Debugging: Why is my pattern returning nothing, or returning the wrong thing? You read the match details to see exactly which characters matched and which groups participated.

All three tasks share a workflow: type the pattern, point it at sample text, and inspect what the engine reports. The Regex Tester is built around that workflow, so the rest of this guide walks through exactly how to use it for each case.

Test a Pattern with Regex Tester

The interface has three moving parts: a pattern box, a flag row, and a test string area. Here is the order of operations for a typical check.

  1. Type or paste the pattern into the /…/ field. You do not need to add the slashes yourself — the tester wraps the literal for you once you toggle a flag.
  2. Toggle the flags you need. Common choices are g to find every match, i to ignore case, and m when your anchors need to fire on every line.
  3. Enter or paste your test string. Use a realistic sample that includes both the matches you want and a few you do not want, so you can verify the pattern does not over-match.
  4. Read the highlighted matches. Every match is highlighted inline in your test string, and a details panel breaks each one down: start index, full matched text, numbered capture groups, and any named groups written with (?<name>…).
  5. Tweak one token at a time. Change a quantifier, swap a character class, or add an anchor and watch the highlights update as you type — that is the fastest way to build intuition for what each piece does.

If the pattern only finds the first match when you expected several, the most common cause is forgetting the g flag. Without it, JavaScript stops at the first match; with it, the engine reports every match in the string.

The Six JavaScript Flags and What Each One Does

JavaScript's RegExp constructor exposes six flags, and the Regex Tester exposes all of them as toggles. The flag row rebuilds the /pattern/flags literal for you so you can copy the exact expression straight into your code.

FlagNameWhat it changes
gglobalFinds every match in the string instead of stopping at the first one.
iignore caseMakes letter matching case-insensitive: /abc/i matches "ABC", "Abc", and "abc".
mmultilineMakes ^ and $ anchor to each line, not just the start and end of the full string.
sdotAllLets the dot . match line break characters as well as any other character.
uunicodeEnables full Unicode handling, including surrogate pairs and Unicode property escapes.
ystickyMatches only starting at lastIndex; useful when you are tokenizing left to right.

For most day-to-day checks you will only need g and possibly i. Reach for m when your input has multiple lines and you want ^…$ to match each one, and reach for s when your pattern needs to span line breaks.

Reading Match Results: Captures, Named Groups, and Zero-Width Hits

The details panel under the test string is where you confirm the pattern is doing what you want. Three things deserve a close look.

Capture groups are the substrings inside parentheses. They are reported in order, starting at index 1, so the first (…) in your pattern is group 1, the second is group 2, and so on. If a group is optional and did not participate in a particular match, the tester marks it clearly so you can see why an optional group came back empty.

Named groups use the syntax (?<name>…) and are reported alongside their numeric position. They let you reference a capture by a readable name instead of an index, which is much easier to maintain in String.match, matchAll, and replace callbacks.

Zero-width matches are where people get stuck. Patterns like a*, ^, \b, or an empty pattern match a position rather than a character. With the g flag, a naive loop over them would re-match the same empty position forever and freeze the browser. The tester advances safely past every zero-width match and reports each position without hanging, which is the right behavior for diagnostic use.

Common Use Cases for a Quick Regex Check

The most frequent reasons to fire up a regex tester fall into a handful of practical buckets.

  • Validating user input. Email, phone number, URL, and slug patterns are quick to prototype against realistic and adversarial samples.
  • Extracting fields from text. Dates, IDs, prices, log severity, and similar tokens are easy to capture and label with named groups.
  • Prototyping find-and-replace. Drop a candidate pattern into the tester first, then use the same expression in String.replace or replaceAll without surprises.
  • Learning the building blocks. Character classes (\d, \w, \s and their negations), quantifiers (*, +, ?, {n,m}), anchors (^, $), alternation (|), and lookahead ((?=…), (?!…)) all reveal themselves by changing one token at a time and watching the highlights update.

One performance note worth keeping in mind: a poorly written pattern can trigger catastrophic backtracking — a form of ReDoS — on certain inputs. Inside the tester that only ever slows down your own browser tab; nothing runs on a server and nothing is shared. In production code the practical takeaway is to anchor your patterns and avoid nested quantifiers on untrusted input.

Regex Building Blocks Worth Trying First

If you are still learning the syntax, the tester doubles as a playground. A short list of tokens to type and watch is enough to build a working mental model.

TokenWhat it matchesTry it on
\dAny digit, 0–9"Order #4729 confirmed"
\wAny word character (letter, digit, underscore)"user_name-42"
\sAny whitespace characterMulti-line input with spaces and tabs
^ and $Start and end of a line (with m) or stringLines like "BEGIN" and "END"
{n,m}Between n and m repetitionsWords of a specific length
(?=…)Positive lookahead — assert without consumingPassword rules and price suffixes

For a fuller list of tokens that stay inside the JavaScript dialect, the Regex Cheat Sheet is a useful side reference while you experiment.

Whichever pattern you end up with, confirm it once in the Regex Tester and you can drop the same /pattern/flags literal into String.match, matchAll, replace, or the RegExp constructor without surprises — because the engine is identical.