BytePane

JavaScript Regex Tester + ReDoS Checker

Test JavaScript RegExp patterns with live matches, capture groups, replace preview, timing, flags, matchAll-friendly examples, and quick ReDoS risk hints.

//g

Pattern Safety Scan

Waiting for pattern

Paste a regular expression to check syntax, matches, capture groups, timing, and obvious ReDoS risks.

Regex Replace Preview

Test JavaScript replace() output with $&, $1, $2, and other numbered capture references before changing production text.

0 replacements

Replacement preview runs against all matches by adding the global flag when needed, so cleanup and redaction patterns show the full output.

Replacement output will appear here.

JavaScript RegExp Code Snippets

Copy the pattern into browser, Node.js, TypeScript, or Deno code using the right API for the job.

Full JavaScript regex guide
Boolean validation
const re = /[A-Z]+/g;
const isMatch = re.test('Sample text 123');
First match with groups
const re = /[A-Z]+/;
const match = re.exec('Sample text 123');
const groups = match?.groups ?? match?.slice(1);
All matches with matchAll
const re = /[A-Z]+/g;
const matches = [...'Sample text 123'.matchAll(re)];
Replace matched text
const re = /[A-Z]+/g;
const output = 'Sample text 123'.replace(re, 'replacement');
Safe dynamic RegExp
function escapeRegex(input) {
  return input.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
const re = new RegExp(escapeRegex(userInput), '');

Regex Cheat Sheet

.

Any character except newline

\d

Digit (0-9)

\w

Word character (a-z, A-Z, 0-9, _)

\s

Whitespace (space, tab, newline)

^

Start of string

$

End of string

*

0 or more

+

1 or more

?

0 or 1 (optional)

{n,m}

Between n and m times

(abc)

Capture group

(?:abc)

Non-capturing group

[abc]

Character class

[^abc]

Negated class

a|b

Alternation (a or b)

(?=abc)

Positive lookahead

JavaScript Regex Quick Reference

JavaScript regex patterns are created with /pattern/flags or new RegExp(pattern, flags). Use test() for a boolean check, exec() for one match with groups, matchAll() for all grouped matches, and replace() or split() when transforming text.

Common JS RegExp flags

g global, i ignore case, m multiline, s dotAll, u Unicode, y sticky, and d match indices.

Best next pages

Open the JavaScript regex guide for RegExp examples, then browse the regex pattern library for copy-paste validation, extraction, and cleanup patterns.

About Regular Expressions

Regular expressions (regex) are the most powerful text pattern matching tool in computing. Every major programming language — JavaScript, Python, Java, Go, Rust, C# — supports regex natively. Originally developed by mathematician Stephen Kleene in the 1950s, regex is used billions of times daily for input validation, data extraction, search-and-replace operations, and log parsing.

What the Tester Reports

Live

matches update in the browser as you edit the pattern, flags, or test string

Groups

capture groups are listed with match index so extraction patterns are easier to debug

ReDoS

common risky shapes are flagged before you copy a pattern into production code

Replace

preview search-and-replace output with capture references before running cleanup, redaction, or log parsing code

Most Common Regex Patterns

Email validation: Use ^[^\s@]+@[^\s@]+\.[^\s@]+$ as a readable front-line filter, then verify deliverability by sending email. Phone numbers: ^\+?[\d\s\-().]+$ is flexible enough for many user interfaces, but server-side code should normalize by country. URLs: https?://[^\s]+ is useful for extraction, while validation is often better handled with URL parsers. For a deeper copy-paste list, open the regex cheat sheet.

Regex Performance Tips

Catastrophic backtracking is the regex performance issue to check first. Nested quantifiers like (a+)+$ can cause exponential time complexity on adversarial input in backtracking engines. This is called ReDoS (Regular Expression Denial of Service). Always test regex patterns with edge cases before deploying to production. Use tighter character classes, anchors, timeouts, or a linear-time engine for untrusted input. BytePane's regex tester shows match timing and flags common risky pattern shapes.

Frequently Asked Questions

How do I write a regex in JavaScript?

Use either a literal such as /pattern/flags or the RegExp constructor: new RegExp(pattern, flags). JavaScript regex supports common flags such as g, i, m, s, u, y, and d, plus methods like test(), exec(), match(), matchAll(), replace(), and split().

What is the difference between JavaScript regex and PCRE or Python regex?

JavaScript RegExp syntax overlaps with PCRE and Python for basics such as groups, alternation, anchors, character classes, and lookahead. Differences appear in engine-specific features, escaping rules, named groups, lookbehind support, Unicode behavior, and replacement syntax.

What regex flavor does this tool use?

BytePane uses JavaScript's built-in RegExp engine. This is the same regex flavor used in Node.js, browsers, TypeScript, and Deno. Most patterns are compatible with PCRE (PHP, Python) with minor differences.

What are regex flags?

Flags modify regex behavior. "g" (global) finds all matches. "i" (case-insensitive) ignores case. "m" (multiline) makes ^ and $ match line starts/ends. "s" (dotAll) makes . match newlines. "u" (unicode) enables Unicode mode.

How do capture groups work?

Parentheses (abc) create a capture group that remembers the matched text. You can reference groups by number ($1, $2) in replacements. Use (?:abc) for non-capturing groups when you need grouping without capturing.

Can I preview regex replacement output?

Yes. Enter replacement text under Replace Preview to transform every match in the test string. JavaScript-style replacement tokens such as $&, $1, and $2 are supported for common search-and-replace workflows.

Does the ReDoS checker prove my regex is safe?

No. The ReDoS checker is a fast browser-side heuristic for common risky shapes such as nested quantifiers, repeated broad wildcards, and repeated alternation. Production systems that accept user input should still use timeouts, review, or a linear-time engine where possible.

Related Tools