Oh MyUtils

Regex Tester - Test Regular Expressions Online

Test and debug regular expressions with real-time matching, capture groups, and syntax highlighting. Includes common patterns library and regex cheat sheet.

Frequently Asked Questions

What is a regular expression (regex)?

A regular expression (regex) is a sequence of characters that defines a search pattern. It's used for pattern matching within strings, enabling operations like validation (emails, phone numbers), search and replace, data extraction, and text parsing. Regex is supported in virtually all programming languages and text editors.

What do the regex flags (g, i, m, s, u) mean?

Regex flags modify how the pattern is matched. 'g' (global) finds all matches, not just the first. 'i' (case-insensitive) ignores letter case. 'm' (multiline) makes ^ and $ match line boundaries, not just string start/end. 's' (dotall) makes . match newline characters. 'u' (unicode) enables full Unicode support including surrogate pairs.

What are the most commonly used regex patterns?

Common patterns include: Email validation (^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$), URL matching (https?://[\w.-]+), Phone numbers (\d{3}-\d{3}-\d{4}), IP addresses (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}), and Hex colors (#[a-fA-F0-9]{6}). Use the Common Patterns library in the tool for one-click insertion.

What are capture groups and how do I use them?

Capture groups, defined by parentheses (), extract specific parts of a match. For example, in '(\d{3})-(\d{4})', group 1 captures the first three digits and group 2 captures the last four. Use (?:...) for non-capturing groups when you need grouping without extraction. Named groups (?<name>...) make references more readable. In replacements, use $1, $2 or $<name> to reference captured values.

Is this regex tester secure?

Yes. This tool runs 100% in your browser using JavaScript's built-in RegExp engine. No patterns or test strings are ever sent to any server. Your data stays completely private on your device. The tool also includes timeout protection to prevent browser freezing from complex patterns (ReDoS protection).

What are best practices for testing regex patterns?

Start simple and add complexity gradually. Test with both matching and non-matching examples. Use the 'g' flag to see all matches. Check edge cases: empty strings, special characters, and boundary conditions. For validation patterns, test invalid inputs too. Use non-capturing groups (?:...) when you don't need the captured value. Avoid greedy quantifiers (.*, .+) when possible, as they can cause performance issues.

Code Examples

// Basic regex matching
const pattern = /\d{3}-\d{4}/g;
const text = "Call 555-1234 or 987-6543";
const matches = text.match(pattern);
console.log(matches); // ["555-1234", "987-6543"]

// Using RegExp constructor with flags
const regex = new RegExp("hello", "gi");
const result = "Hello HELLO hello".match(regex);
console.log(result); // ["Hello", "HELLO", "hello"]

// Capture groups
const emailRegex = /([\w.-]+)@([\w.-]+)/;
const email = "user@example.com";
const [, username, domain] = email.match(emailRegex);
console.log(username, domain); // "user" "example.com"

// Replace with capture groups
const formatted = "2026-02-01".replace(/(\d{4})-(\d{2})-(\d{2})/, "$2/$3/$1");
console.log(formatted); // "02/01/2026"

Related Tools