Regex Tester with Explanation — Free Online Tool
Test regular expressions in real-time with live match highlighting, group capture, and plain-English explanations.
Cheatsheet — click to insert
What is a Regular Expression?
A regular expression (regex or regexp) is a sequence of characters that defines a search pattern. They're used for string searching, validation, text extraction, and replacement. Regex is supported in virtually every programming language and is an essential tool for any developer working with text processing.
Regex Syntax Quick Reference
.— Matches any character except newline^/$— Start / end of string (or line in multiline mode)*/+/?— 0 or more / 1 or more / 0 or 1{n,m}— Between n and m repetitions[abc]— Character class — matches a, b, or c[^abc]— Negated character class(abc)— Capturing group(?:abc)— Non-capturing group\d/\w/\s— Digit / word character / whitespacea|b— Alternation — matches a or b
Common Regex Patterns
- Email:
[\w.+-]+@[\w-]+\.[a-zA-Z]{2,} - URL:
https?://[\w\-._~:/?#[\]@!$&'()*+,;=%]+ - IPv4:
(\d{1,3}\.){3}\d{1,3} - Phone (US):
(\+1\s?)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4} - Hex color:
#([a-fA-F0-9]{6}|[a-fA-F0-9]{3}) - Date (YYYY-MM-DD):
\d{4}-\d{2}-\d{2}
Frequently Asked Questions about Regular Expressions
What is the difference between .* and .+ in regex?
The asterisk (*) means "zero or more" of the preceding element, while plus (+) means "one or more." The pattern .* matches any string including empty strings, while .+ requires at least one character. Both are greedy by default — they match as much as possible. Add ? to make them lazy (match as little as possible): .*? and .+?.
What do the regex flags g, i, m, and s do?
The g (global) flag finds all matches instead of stopping after the first. The i flag makes the match case-insensitive. The m (multiline) flag makes ^ and $ match the start and end of each line rather than the entire string. The s (dotAll) flag makes the dot match newline characters. Combine flags as needed: /pattern/gim.
How do I match a literal dot, parenthesis, or other special characters?
Escape special regex characters with a backslash. A literal dot is . (without the backslash, dot matches any character). A literal parenthesis is ( and ). Other characters that need escaping: ^ $ | ? * + { } [ ]. For example, to match the URL example.com literally, write /example.com/ — otherwise the dot would match any character.
What is the difference between a greedy and a lazy quantifier?
Greedy quantifiers (*, +, {n,m}) try to match as much as possible while still allowing the overall pattern to match. Lazy (non-greedy) quantifiers (*?, +?, {n,m}?) match as little as possible. For example, given <b>bold</b>, the greedy /<.*>/ matches the entire string, while the lazy /<.*?>/ matches only <b>.
Related Developer Tools
- CORS Error Debugger — free online tool at devbit.dev
- HTTP Status Code Explorer — free online tool at devbit.dev
- JWT Decoder & Inspector — free online tool at devbit.dev
- View all free developer tools