Regex Tester

Test JavaScript regular expressions with flags, live match results, capture groups, and replace preview.

Pattern & Test Text

0 characters

Replace Preview

Optional
Replacement preview will appear here...

Highlighted Matches

0 matches
Match highlights will appear here...

Match Details

Capture groups included
Status
No regex tested yet.
`matchAll()` is useful for collecting all matches and capture groups, but it requires a regex with the global `g` flag when used directly with a `RegExp` object.

How it works

JavaScript uses the `RegExp` object for pattern matching, and tools like this typically build a regex from a user pattern plus selected flags such as `g`, `i`, `m`, `s`, and `u`. To inspect every match and its captured groups, `String.prototype.matchAll()` is especially convenient, but it requires a global regex when passed a `RegExp` instance.

  • g finds all matches, not just the first one.
  • i makes matching case-insensitive.
  • m makes `^` and `$` work per line in multiline text.
  • s makes `.` match newline characters too.
  • u improves Unicode handling in JavaScript regex parsing and matching.

Common regex patterns

Use case Pattern
Email address ^[\w.+-]+@[\w-]+\.[a-zA-Z]{2,}$
Indian mobile number ^[6-9]\d{9}$
URL ^https?:\/\/[\w.-]+(\.[a-zA-Z]{2,})+[\S]*$
Hex color code ^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$
Date (YYYY-MM-DD) ^\d{4}-\d{2}-\d{2}$

Frequently Asked Questions

This tool uses JavaScript's native RegExp engine, the same one used in browsers and Node.js. Syntax may differ slightly from PCRE (PHP) or Python's re module.

g finds all matches instead of just the first. i makes matching case-insensitive. m makes ^ and $ match per line. s lets . match newlines. u enables full Unicode-aware matching.

In JavaScript, String.replace() only replaces the first match unless the regex has the global (g) flag enabled. Check the g checkbox to replace all matches.

Use $1, $2, and so on for numbered capture groups. For named groups defined with (?<name>...), use $<name> in the replacement instead.

Usually caused by unescaped special characters, mismatched brackets or parentheses, or invalid flag combinations. Remember to escape characters like . ( ) [ ] when treating them literally.

Yes, paste multiline text into the test area and enable the m (multiline) flag if you want ^ and $ to match line boundaries rather than the whole text block.