Pattern & Test Text
Replace Preview
Highlighted Matches
Match Details
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.