Skip to main content
Back to all tools

Regex Tester

Test regular expressions with live match highlighting and multi-language code snippets.

//g

Flags

Common Patterns

Code Snippet

javascript
const regex = /pattern/g;
const match = regex.exec(str);
const allMatches = [...str.matchAll(regex)];
const result = str.replace(regex, replacement);

Frequently Asked Questions

What is a regular expression (regex)?

A regex is a pattern that describes a set of strings. It's used for searching, matching, and replacing text. Example: \d{3}-\d{4} matches phone number patterns like 555-1234. Tip: start simple and build up — regex can be composed incrementally by adding one rule at a time.

What are the most common regex patterns?

\d (digit), \w (word character), \s (whitespace), . (any character), * (0+), + (1+), ? (optional), {n,m} (range), ^ (start), $ (end), [abc] (character class), (group). Tip: use \b for word boundaries to avoid partial matches — \bcat\b matches 'cat' but not 'category'.

What are regex flags?

Flags modify regex behavior: g (global — find all matches), i (case-insensitive), m (multiline — ^ and $ match line boundaries), s (dotAll — . matches newlines), u (Unicode). Tip: always use the g flag when you want to find all matches, not just the first one.

How do I validate an email with regex?

A simple email pattern is [^@\s]+@[^@\s]+\.[^@\s]+. However, the full RFC 5322 email spec is extremely complex. Tip: for production validation, use a simple regex to catch obvious errors, then verify by sending a confirmation email. Don't over-validate — many valid emails have unusual formats.

What is the difference between greedy and lazy matching?

Greedy quantifiers (*, +) match as much text as possible. Lazy quantifiers (*?, +?) match as little as possible. Example: for '<b>bold</b>', <.*> matches the entire string (greedy) while <.*?> matches just <b> (lazy). Tip: use lazy matching when extracting content between delimiters.