Test regular expressions against any text in real time. See all matches highlighted with a count β ideal for building and debugging regex patterns.
Flags
Global matching is always enabled.
Enter a pattern to start testing
Test JavaScript regular expressions against sample text in real time. Enter a pattern, choose optional flags, and inspect match counts, indexes, matched text, and capture groups without leaving your browser.
\\bcat\\b.| Flag | Purpose |
|---|---|
g | Find every match. This tester enables global matching automatically. |
i | Ignore letter case. |
m | Make ^ and $ work at line boundaries. |
s | Let . match newline characters. |
u | Enable Unicode code point behavior. |
Invalid syntax appears immediately with the JavaScript engine error. A valid pattern reports zero matches when no text matches.
| Use case | Pattern |
|---|---|
| Whole word | \\bword\\b |
| Email address | ^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$ |
| URL | https?://[^\\s]+ |
| US phone number | \\(?\\d{3}\\)?[-.\\s]?\\d{3}[-.\\s]?\\d{4} |
| ISO date | \\d{4}-\\d{2}-\\d{2} |
Patterns should match the actual input format. For production validation, combine regular expressions with type checks and business rules instead of relying on one expression for every requirement.
Parentheses create capture groups. For example, (?<user>[^@]+)@(?<domain>[^@]+) separates an email into user and domain portions. Match details include each full match, its zero-based index in the test string, and captured values.
const expression = /(?<user>[^@]+)@(?<domain>[^@]+)/g;
const text = "ada@example.com";
const match = expression.exec(text);
console.log(match?.groups?.user); // ada
console.log(match?.groups?.domain); // example.com
console.log(match?.index); // 0
const pattern = new RegExp("\\bcat\\b", "gi");
const matches = [..."A cat and another CAT".matchAll(pattern)];
console.log(matches.map((match) => match[0]));
// ["cat", "CAT"]
JavaScript and Python share many regex concepts, but syntax and supported flags differ. Always test patterns in the same language and runtime used by your application.
import re
pattern = re.compile(r"\bcat\b", re.IGNORECASE)
matches = pattern.findall("A cat and another CAT")
print(matches)
{1,20} when input length is known.(?:...) when you do not need a captured value.This tool is provided for general informational and utility purposes only. Results may be inaccurate, incomplete, outdated, or contain errors. Always verify results before relying on or using them.
Some tools may use AI, automated processing, third-party services, or server-side processing. Do not rely on these tools as a substitute for professional advice.
Use at your own risk. BestToolOnline makes no guarantees regarding the accuracy, reliability, completeness, availability, or suitability of results, to the maximum extent permitted by applicable law.
See our Terms of Service and Privacy Policy for complete details.