Regex Tester Online for JavaScript

Test a JavaScript pattern against your text. Copy matches or capture groups, preview replacements, or export JavaScript.

Flags
Export JavaScript

Enter a pattern to export JavaScript.

Match Highlights

Matches will highlight here as you type.

Match Results
0 matches

Enter a regex pattern and test string above to see matches.

Example

Pattern\b\w+@\w+\.\w+\b
Testhello world user@example.com

JavaScript regex test workflow

Test a JavaScript regex step by step

Whatever you call the tool, the job is the same: prove that a pattern matches the right text in the same JavaScript RegExp engine used by browsers and Node.js. Start with the exact strings your code receives, including spaces, punctuation, copied user input, empty lines, and malformed values.

The safest JavaScript regex test uses a small sample bank. Add examples that should pass, examples that should fail, and at least one edge case that previously broke. Then toggle flags one at a time, inspect capture groups, and preview replacements before moving the expression into frontend, TypeScript, or Node.js code.

Paste the pattern body

Use the JavaScript pattern body without slash delimiters, then choose flags with the toggles. For example, enter \b\w+@\w+\.\w+\b and enable g instead of pasting /\b\w+@\w+\.\w+\b/g.

Test pass and fail samples

Open Test cases to check inputs that should match and inputs that should fail. Run them together to catch loose anchors, overmatching, and regressions when you change a pattern or flag.

Inspect matches, groups, and replacements

Check match ranges, capture groups, named groups, and replacement output. A JavaScript regex can look correct with RegExp.test() while still returning the wrong group or formatting replacement.

Search queryWhat to verifyBest next step
regex testerCheck a pattern against real text and see every match immediately.Use the live tester on this page, then open the regex cheat sheet when syntax is unclear.
regex test jsConfirm how JavaScript RegExp handles flags, anchors, groups, Unicode, and lastIndex behavior.Use the JavaScript regex test guide after running the first check.
javascript regex testerDebug a browser or Node.js pattern before copying it into app code.Use the JavaScript regex tester workflow for a deeper production checklist.

Regex examples to paste into the JavaScript tester

Email-like values

Pattern
\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b
Flags
gi
Test string
ok: alex@example.com bad: alex@@example also ok: team+alerts@sub.example.org

Good for checking global matches, case-insensitive matching, and obvious malformed values.

Slug validation

Pattern
^[a-z0-9]+(?:-[a-z0-9]+)*$
Flags
none
Test string
regex-tester Regex Tester regex--tester regex-tester-2026

Good for testing anchors, whole-string validation, and repeated groups.

Named capture groups

Pattern
(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})
Flags
g
Test string
Published 2026-04-20 and updated 2026-05-01.

Good for checking JavaScript named groups before formatting dates or parsing logs.

JavaScript regex reference

Use this regex tester before you rely on RegExp.test(), matchAll(), or replace()

Many searches that trigger this homepage are really asking two connected questions: “Where can I test this regex online?” and “How will the same pattern behave in JavaScript?” This page answers both by letting you test the pattern visually first, then move the exact regex into browser or Node.js code with fewer surprises.

If you are searching for a JavaScript regex tester or JavaScript RegExp test, use the table below to choose the code path you actually need. The live tester helps you confirm the pattern, flags, capture groups, and replacement output before you switch to `RegExp.test()`, `String.matchAll()`, or `String.replace()`.

JavaScript methodWhen to use itWhat to verify in the tester first
RegExp.test()Return a quick true or false for a validation rule.Confirm anchors, case sensitivity, and edge-case failures before shipping the boolean check.
String.matchAll()Collect every match and capture group from a longer string.Verify global matching, named groups, and match order in the results panel before looping in code.
String.replace()Transform text with capture groups and backreferences.Use Replace mode here first so you can inspect the output before wiring it into app logic.

Validate a full string with RegExp.test()

Use the live tester to prove the anchors and casing rules first, then move the same pattern into JavaScript.

const slugPattern = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;

const samples = ["regex-tester", "Regex Tester", "regex--tester"];

for (const value of samples) {
  console.log(value, slugPattern.test(value));
}

This mirrors the common 'regex test js' search intent: validate one value quickly, but make sure the failure cases are visible before the boolean check lands in production.

Inspect all matches with String.matchAll()

This is the safest handoff when your regex tester session already shows multiple matches and named groups.

const datePattern = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/g;
const text = "Published 2026-04-20 and updated 2026-05-01.";

for (const match of text.matchAll(datePattern)) {
  console.log(match[0], match.groups);
}

If the tester highlights the wrong match or group, fix the pattern here before you depend on match iteration in your JavaScript code.

Preview replacements before String.replace()

Searchers looking for a JavaScript regexp test often need to reformat text, not just detect a match.

const isoDate = /(\d{4})-(\d{2})-(\d{2})/g;
const text = "Ship date: 2026-04-20";

const formatted = text.replace(isoDate, "$2/$3/$1");
console.log(formatted); // Ship date: 04/20/2026

Replace mode on this page lets you catch backreference mistakes before they spread through user-facing strings or exports.

Frequently Asked Questions

What regex flavor does this tool use?

This tester uses JavaScript's native RegExp engine — the same engine that runs in Node.js and every modern browser. It supports standard regex syntax plus JavaScript-specific features like named capture groups (?<name>...), lookaheads, lookbehinds, and Unicode property escapes with the u flag.

How do I run a regex test for JavaScript?

Paste the pattern body into the regex field without slash delimiters, choose the same flags your code uses, and add realistic pass and fail strings. Then inspect highlighted matches, capture groups, match positions, and replacement output before copying the RegExp into browser, TypeScript, or Node.js code.

Should I paste /pattern/g or only the pattern?

Enter only the pattern body in the regex field and use the flag toggles for g, i, m, s, u, and y. For example, enter ^[a-z0-9-]+$ as the pattern, then leave flags off for a whole-string slug validation check.

How do I test a regex for email validation?

Open the Patterns library (click Patterns in the toolbar) and select "Email Address" — it loads a ready-made pattern and sample test string. Or type your own pattern in the regex field and paste a list of email addresses in the test string area. Matches highlight in real-time as you type.

How do I use capture groups and backreferences?

Wrap parts of your pattern in parentheses to create capture groups: (\d{4})-(\d{2})-(\d{2}). The match results panel shows each group's value. In Replace mode, reference them with $1, $2, $3 in the replacement field — for example, reformat a date from YYYY-MM-DD to MM/DD/YYYY using the replacement $2/$3/$1.

What do the regex flags mean?

g (global) finds all matches instead of stopping at the first. i (case-insensitive) makes the pattern match regardless of letter case. m (multiline) makes ^ and $ match the start/end of each line rather than the whole string. s (dotAll) makes . match newlines. u (unicode) enables full Unicode support and property escapes. y (sticky) matches only at the current position in the string. See the full flags reference →

Can I share my regex with someone?

Yes — click the Share button to copy a URL that encodes your pattern, flags, test string, and any active replacement after the # in the link. Anyone who opens that link will see your exact regex setup. No account or login is required.

Is my test data sent to a server?

Matching runs entirely in your browser. New share links keep the pattern, test string, and any active replacement after the #, which the browser omits from the page request. Anyone with the link can read them. Older links may carry those values in the query string.

How is this different from regex101?

regex101 is powerful but dense — it supports multiple regex flavors, has a full explanation panel, and has many configuration options. This tool focuses on JavaScript regex specifically, with a cleaner interface and faster load time. It's designed for quick testing during development, not for learning regex from scratch.

How to test a pattern

Use Test cases to check values that should match and values that must fail. That exposes loose anchors, overly broad character classes, escaping mistakes, and unexpected global or multiline behavior. Patterns run locally in your browser; the text entered into the tester is not submitted to a regex-processing service.

Extracting Unix timestamps from logs? Copy the matching group and paste the values into the batch timestamp converter.

Escape plain text or convert a pattern to new RegExp code.

Need to separate a string into fields? Use the JavaScript regex split tester.

If the same check changes between calls, trace RegExp.test() and lastIndex with the global or sticky flag.

Validating fields for a form or import? Try the time format regex examples for valid hours and minutes or the MAC address regex examples for hex pairs and consistent separators. Validate IPv4 addresses with runnable examples for octet limits, leading zeros, ports, and CIDR suffixes.

Use the included examples and cheat sheet when debugging email, slug, date, identifier, or extraction patterns. This tool follows JavaScript RegExp behavior, which can differ from PCRE, Python, Java, and .NET engines.