Skip to content

JavaScript Regex Tester

Test JavaScript regular expressions against sample text. Change the flags and see which matches the pattern finds.

Runs in your browser Free, no sign-up
Loading tool workspace...

What is Regex Tester?

This regex tester lets you try a regular expression against real text and see what it matches before you put it in your code. Enter the pattern (for example \d{3}-\d{4} or ^[\w.+-]+@[\w-]+\.[\w.]+$), set the flags, and paste your test string: every match is highlighted in place and the total number of matches is shown, updating as you type.

It uses JavaScript's own regular expression engine, so the behavior matches what you get with RegExp, String.prototype.match, replace and matchAll in browsers and Node.js. Invalid patterns show the engine's error message, such as an unterminated group or a nothing-to-repeat error.

How to use Regex Tester

  1. Type your regular expression in the Pattern box, without the surrounding slashes.
  2. Set the flags, for example g (global), i (ignore case), m (multiline) or s (dotAll).
  3. Paste the text to test against into the Test String box.
  4. Review the highlighted matches and the match count; refine the pattern until it matches exactly what you want.

Key features

  • Live highlighting of every match in the test string
  • Match count that updates as you type
  • Supports all JavaScript flags: g, i, m, s, u, y, d
  • Clear error messages for invalid patterns
  • Uses the same regex engine as browsers and Node.js
  • Runs locally; test data never leaves your browser

Common use cases

  • Building validation patterns for emails, phone numbers, postcodes and IDs
  • Writing search-and-replace patterns for code editors and scripts
  • Extracting values from log lines and stack traces
  • Testing route patterns and URL matchers
  • Learning regular expression syntax interactively

Technical details & standards

Patterns are compiled with new RegExp(pattern, flags) and matched with matchAll, so the g flag is always applied when counting and highlighting matches. JavaScript supports the flags g (global), i (case-insensitive), m (^ and $ match at line breaks), s (. matches newlines), u (Unicode mode, needed for \p{…} property escapes), y (sticky), d (match indices) and v (Unicode sets, in newer engines).

JavaScript regex syntax is close to PCRE, Python and Java but not identical: possessive quantifiers and atomic groups are missing, lookbehind ((?<=…)) is supported in modern engines, and named groups use (?<name>…). Test in the flavor your code actually runs to avoid surprises.

Match order IDs in a log

Try this input in the workspace above.

  1. Paste order=AB-042 and order=ab-043 on separate lines. Enter [A-Z]{2}-[0-9]{3} as the pattern.

Result: The first line matches AB-042. Enable the i flag to also match ab-043, and use the g flag to find all occurrences. Enter the pattern without surrounding slash delimiters.

Frequently asked questions

Which regex flavor does this tester use?

JavaScript (ECMAScript), via the browser's RegExp engine. Results match browsers and Node.js. Most simple patterns behave the same in PCRE, Python and Java, but advanced features such as possessive quantifiers differ.

What do the regex flags g, i and m do?

g finds all matches instead of stopping at the first, i ignores case, and m makes ^ and $ match at the start and end of each line rather than the whole string. s lets . match newline characters.

How do I match a literal dot, plus sign or bracket?

Escape it with a backslash: \. matches a dot, \+ a plus sign and \[ a square bracket. Inside a character class such as [.+], most characters are literal and need no escaping.

Why does my pattern match too much?

Quantifiers such as * and + are greedy and match as much as possible. Add ? to make them lazy (.*? instead of .*), or use a negated character class such as [^"]* to stop at a specific character.

Is my data safe?

Processing happens locally in your browser. Tool input is not sent to CodeUnpack servers.

Does it work offline?

Once the page has loaded, this tool can process input without an internet connection.

More validators & checkers tools

View all