Dev Tools

Regex Tester

Write a regex pattern, paste test text, and see every match highlighted in real time. Supports flags, capture groups, and quick pattern presets.

Pattern
/ /
Test String No matches
Matches highlighted in yellow
Matches
Enter a pattern and test string to see matches.

Frequently Asked Questions

What do the regex flags g, i, m, and s do?

The four most common regex flags: (g) global — finds all matches rather than stopping at the first. Without this flag, regex returns only the first match. (i) case-insensitive — makes the pattern match regardless of letter case: /hello/i matches 'Hello', 'HELLO', 'hello'. (m) multiline — changes the behavior of ^ and $ anchors: instead of matching the start/end of the entire string, they match the start/end of each line. (s) dotAll (also called 'single-line') — makes the dot (.) match newline characters as well, which it doesn't do by default. Flags can be combined: /pattern/gi finds all matches case-insensitively.

How do capture groups work in regular expressions?

Capture groups let you extract specific parts of a match. Wrap part of a pattern in parentheses to create a capture group: /(\d{4})-(\d{2})-(\d{2})/ on '2025-01-15' captures group 1 = '2025', group 2 = '01', group 3 = '15'. Non-capturing groups use (?:...) syntax — they group without capturing. Named capture groups use (?...) syntax: /(?\d{4})/ — accessible as match.groups.year. In JavaScript, match results expose capture groups via the .slice(1) array or .groups for named groups. In replacement strings, $1 refers to group 1, $2 to group 2, and $ to named groups.

What is the difference between .* and .+? in regex?

The dot (.) matches any character except newlines (unless the s flag is set). Quantifiers control repetition: * means zero or more, + means one or more, ? means zero or one. So: .* matches zero or more of any character (greedy by default), .+ matches one or more of any character, .? matches zero or one character. When followed by ?, quantifiers become lazy (non-greedy): .*? matches as few characters as possible. Example: on 'text', the pattern <.*> greedily matches the whole string; <.*?> lazily matches just ''. Understanding greedy vs lazy matching is one of the most important practical regex skills.

How do I match an email address with regex?

A practical email-matching regex: /[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}/. This matches most real-world email addresses: one or more allowed characters, @ symbol, domain part with allowed characters and dots, then a TLD of 2+ letters. It won't match every technically valid email (the RFC 5322 spec is extremely complex) but handles 99%+ of real addresses. For critical validation (sign-up forms), always combine regex with server-side verification and/or a verification email. A regex match confirms format, not deliverability.

What are lookaheads and lookbehinds in regex?

Lookaheads and lookbehinds are zero-width assertions — they match a position in the string without consuming characters. Positive lookahead (?=...) asserts that what follows matches: /\w+(?=\s*:)/ matches a word only if followed by a colon. Negative lookahead (?!...) asserts what follows does NOT match: /foo(?!bar)/ matches 'foo' not followed by 'bar'. Positive lookbehind (?<=...) asserts what precedes matches: /(?<=\$)\d+/ matches digits preceded by a dollar sign. Negative lookbehind (?

How to Use the Regex Tester

Enter a regular expression pattern in the pattern box (without surrounding slashes), toggle flags as needed, and paste your test text. Every match is highlighted in yellow in the test string panel and listed below with its position and capture groups.

Common Regex Patterns

Email: [a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,} — URL: https?://[^\s/$.?#].[^\s]* — Phone (US): (\+?1[\s\-.]?)?\(?\d{3}\)?[\s\-.]?\d{3}[\s\-.]?\d{4} — IPv4: \b(?:\d{1,3}\.){3}\d{1,3}\b

Key Concepts

The g flag finds all matches; without it, only the first match is found. The i flag makes matching case-insensitive. Wrap parts of a pattern in parentheses () to create capture groups — this tool shows group values for each match. Use (?:...) for non-capturing groups when you want to group without capturing.