Test regular expressions with live validation and match highlighting. Perfect for debugging patterns and learning regex.
Common Flags:
Enter pattern and test string
Results will appear here
.
- Any character\\d
- Any digit\\w
- Word character\\s
- Whitespace+
- One or more*
- Zero or more?
- Zero or one{n,m}
- Between n and m^
- Start of string$
- End of string\\b
- Word boundary\\B
- Non-word boundaryRegular expressions (regex) are powerful pattern-matching tools used to search, validate, and manipulate text. They provide a concise way to describe complex text patterns using special characters and syntax rules.
Used in programming languages (JavaScript, Python, Java), text editors (VS Code, Sublime), command-line tools (grep, sed), databases (MySQL, PostgreSQL), and web development frameworks.
Enter your regex pattern in the Pattern field. Start simple with literal text, then add special characters for complex matching.
Use flags to modify behavior: 'g' for global matching, 'i' for case-insensitive, 'm' for multiline mode.
Enter sample text to see matches highlighted in real-time. View detailed results including match positions and capture groups.
Iterate on your pattern, test edge cases, and use our reference guide to learn new syntax elements.
.
Any character except newline\\d
Any digit [0-9]\\D
Any non-digit\\w
Word char [a-zA-Z0-9_]\\W
Non-word character\\s
Whitespace [ \\t\\n\\r]\\S
Non-whitespace*
Zero or more+
One or more?
Zero or one (optional){n}
Exactly n times{n,}
n or more times{n,m}
Between n and m times*?
Non-greedy (lazy)^
Start of string/line$
End of string/line\\b
Word boundary\\B
Non-word boundary\\A
Start of string only\\Z
End of string only(abc)
Capturing group(?:abc)
Non-capturing groupa|b
Alternation (or)\\1
Backreference(?=abc)
Positive lookahead(?!abc)
Negative lookahead[abc]
Any of a, b, or c[^abc]
Not a, b, or c[a-z]
Lowercase letters[A-Z]
Uppercase letters[0-9]
Digits[a-zA-Z0-9]
Alphanumericg
Global (all matches)i
Case insensitivem
Multiline modes
Dot matches newlineu
Unicode modey
Sticky mode^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$
Validates basic email format with username, @ symbol, domain, and TLD.
^(\\+1[- ]?)?\\(?([0-9]{3})\\)?[- ]?([0-9]{3})[- ]?([0-9]{4})$
Matches various US phone number formats: (555) 123-4567, 555-123-4567, +1 555 123 4567.
^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[@$!%*?&])[A-Za-z\\d@$!%*?&]{8,}$
Requires 8+ characters with lowercase, uppercase, digit, and special character.
https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)
Finds HTTP and HTTPS URLs in text content.
^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13})$
Matches Visa, MasterCard, and American Express card formats.
^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$
Validates IPv4 addresses with proper range checking (0-255 per octet).
Use precise patterns rather than overly broad ones:
.+
(matches everything)[A-Za-z0-9]+
(specific characters)Anchor patterns to prevent unintended matches:
\\d{3}
(matches 123 in 123456)^\\d{3}$
(exactly 3 digits)Document complex patterns and use named groups for clarity. Consider breaking very complex patterns into multiple simpler ones.
Avoid nested quantifiers that can cause exponential time complexity:
(a+)+b
a+b
Understand the difference between greedy and lazy quantifiers:
<.+>
(matches <a>text</a>)<.+?>
(matches <a> only)Test with empty strings, very long inputs, special characters, and malformed data. What works for normal input might fail catastrophically on edge cases.
A: .* matches zero or more of any character (including empty string), while .+ matches one or more (requires at least one character). Use .+ when you need to ensure something exists, .* when optional.
A: By default, . doesn't match newline characters, and ^ and $ only match string start/end. Use the 'm' flag for multiline mode (^ and $ match line boundaries) and 's' flag for dotall mode (. matches newlines).
A: Escape special characters with backslashes: \. \+ \* \? \[ \] \( \) \ \^ \$ \| \\. Inside character classes [like this], most characters don't need escaping except ] ^ - and \.
A: Capture groups (parentheses) save matched portions for later use. In "Hello (\\w+)", the word after "Hello " is captured as group 1. Use \\1, \\2, etc. to reference captured groups within the same pattern, or access them programmatically in your code.
A: Use regex for pattern matching, validation, and complex text processing. Use simple string methods (contains, startsWith, etc.) for literal text searches - they're faster and more readable. If you can solve it simply without regex, do so.
A: Break complex patterns into smaller parts, use non-capturing groups (?:...) to organize without creating unnecessary captures, add comments in your code explaining what each part does, and consider using multiple simpler regexes instead of one complex one.
A: Common causes include catastrophic backtracking from nested quantifiers, overly broad patterns that force excessive backtracking, or missing anchors. Use atomic groups, possessive quantifiers, or break up the text into smaller chunks for processing.
A: Yes, while basic syntax is similar, there are differences in supported features, performance, and behavior. JavaScript, Python, Java, and .NET all have slightly different regex implementations. Our tester uses JavaScript's regex engine, so results match browser/Node.js behavior.