Skip to content

JavaScript Regex Tester — Test and Debug JS Regular Expressions Online

Free

Test JavaScript regular expressions live with match highlighting, capture groups, and flag support. Free, runs in your browser using the JS RegExp engine.

js regex tester onlinetest regex javascriptjavascript regex online
All Developer Tools

Settings guide

JavaScript regex flags:

  • ·`g` (global) — Find all matches, not just the first. Required for matchAll() and global .replace().
  • ·`i` (case-insensitive)/hello/i matches "Hello", "HELLO", "hElLo".
  • ·`m` (multiline)^ and $ match the start/end of each line, not just the whole string.
  • ·`s` (dotAll). matches newlines (\n). Without s, . skips newline characters.
  • ·`u` (unicode) — Enables full Unicode matching. Required for matching Unicode code points above U+FFFF and Unicode property escapes (\p{Letter}).
  • ·`d` (indices) — Adds indices array to match result with start/end positions for each group.

Named capture groups: JavaScript (ES2018+) supports (?<name>...) syntax. Named groups appear in match.groups.name and can be used in replacement strings as $<name>.

Format comparison

JavaScript RegExp vs Python re module: The biggest syntax differences: Python uses (?P<name>...) for named groups (JS uses (?<name>...)), Python uses re.VERBOSE for comments in patterns (JS has no equivalent), and Python's re.match() only matches at the start of the string (JS .match() searches the whole string). Test your patterns in the language that will run them.

Online tester vs browser DevTools console: DevTools console lets you test regex with /pattern/flags.test("string") but shows only true/false without match highlighting. This tester visualises every match, group, and position — significantly faster for complex pattern development.

How it works

1

Compile the pattern

The regex pattern and flags are compiled using JavaScript's native RegExp constructor — the same engine that runs in V8 (Chrome, Node.js), SpiderMonkey (Firefox), and JavaScriptCore (Safari).

2

Execute against test string

matchAll() is called with the global flag, or exec() iteratively for non-global patterns. Every match position, length, and capture group value is recorded.

3

Highlight and annotate

Matching substrings are highlighted in the test string. Capture groups are annotated by index and name. Non-matching regions are shown in neutral colour.

4

Generate code snippets

Ready-to-use JavaScript code is generated: String.prototype.match(), matchAll(), replace(), and test() calls using your exact pattern and flags. Copy directly into your codebase.

About this format

JavaScript's `RegExp` engine has specific syntax, flags, and behaviours that differ from Python, PHP, and other languages. Testing a regex against a real string with the actual JavaScript engine — not a generic regex parser — ensures what you test is exactly what runs in production.

Write your pattern, select your flags, and enter your test string. All matches are highlighted, capture groups are labelled by name or index, and match count is shown. The tool generates the corresponding `String.prototype.match()`, `.replace()`, and `.test()` code snippets ready to paste into your JavaScript.

Frequently asked questions

What JavaScript regex engine does this use?+
This tester runs your regex using the browser's native JavaScript RegExp engine — V8 in Chrome, SpiderMonkey in Firefox, JavaScriptCore in Safari. The behaviour is identical to what your JavaScript code will execute, including any engine-specific quirks.
How do I use named capture groups in JavaScript?+
Use (?<name>...) syntax: /(?<year>\d{4})-(?<month>\d{2})/. The matched values are in match.groups.name. In replacement strings, use $<name>: 'str'.replace(/(?<y>\d{4})/, '$<y> AD'). Named groups require ES2018 or later.
Why does my regex match in the tester but not in my code?+
The most common causes: missing the g (global) flag when expecting multiple matches, forgetting to call matchAll() for global patterns (match() with g returns only the full matches, not groups), or using a pattern that works on one V8 version but not another due to Unicode/lookbehind feature availability.
What is the difference between .match() and .matchAll()?+
String.match(regex) with the g flag returns an array of all full match strings — capture groups are not included. String.matchAll(regex) returns an iterator of match objects, each with the full match and all capture groups. For patterns with groups where you need all matches, always use matchAll().
How do I match a literal dot or special character?+
Escape it with a backslash: \. matches a literal period (. without the backslash matches any character). Other characters that need escaping: \ ^ $ . | ? * + ( ) [ ] { }. In a character class [ ], fewer characters need escaping — only ], \, ^, and -.

Related tools and guides