Regex Tester
Test regular expressions against text and see all matches highlighted. Essential for developers working with pattern matching, data validation, or text processing. Debug and refine your regex patterns in real-time with visual feedback showing exactly what your expression matches.
Frequently asked questions
What is a regular expression (regex)?
A regular expression is a sequence of characters that defines a search pattern. Regex is used for finding, matching, and manipulating text based on patterns rather than exact strings. It's incredibly powerful for tasks like validating email addresses, extracting data from text, find-and-replace operations, and parsing log files.
How do I test if my regex pattern works?
Enter your regex pattern in the pattern field and paste your test text in the text area. The tool will highlight all matches in real-time, showing you exactly what your pattern captures. If nothing highlights, your pattern isn't matching. Use this visual feedback to refine your pattern until it matches exactly what you need.
What are common regex flags and what do they do?
The most common flags are: 'g' (global) finds all matches instead of just the first one, 'i' (case-insensitive) ignores uppercase/lowercase differences, 'm' (multiline) makes ^ and $ match line starts/ends instead of just string start/end, and 's' (dotall) makes . match newline characters. Combine flags like 'gi' for global case-insensitive matching.
How do I match email addresses or URLs with regex?
For email: try /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/ for basic validation. For URLs: /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/ works for most cases. Note that perfect email/URL validation is extremely complex - these patterns handle most common cases.
What's the difference between .* and .+?
The dot (.) matches any character. The asterisk (*) means 'zero or more times' while plus (+) means 'one or more times'. So .* matches zero or more of any character (including matching nothing), while .+ requires at least one character to match. For example, 'a.*b' matches 'ab' or 'a123b', but 'a.+b' only matches 'a123b'.
How do I make my regex non-greedy?
By default, quantifiers like *, +, and {n,m} are greedy - they match as much as possible. Add a question mark (?) after the quantifier to make it non-greedy (lazy), matching as little as possible. For example, in the text '<div>hello</div><div>world</div>', /<div>.*<\/div>/ matches the entire string (greedy), while /<div>.*?<\/div>/ matches each tag separately (non-greedy).
What are capturing groups and how do I use them?
Capturing groups use parentheses () to extract specific parts of a match. For example, /user-(\d+)/ captures the numeric user ID. The captured value can be accessed in most languages using match groups. Use (?:...) for non-capturing groups when you need grouping for quantifiers but don't want to capture the value.
How can I test regex for log file parsing?
Paste sample log entries into the test string area and create patterns to extract timestamps, IP addresses, status codes, or error messages. Visual highlighting shows exactly what matches, helping you refine patterns before deploying them in log analysis tools like Logstash, Splunk, or custom scripts.
What are lookaheads and lookbehinds in regex?
Lookaheads (?=...) and lookbehinds (?<=...) assert that a pattern exists ahead or behind without including it in the match. For example, /\d+(?= dollars)/ matches numbers followed by ' dollars' but only captures the number. Negative lookaheads (?!...) and negative lookbehinds (?<!...) assert the pattern does NOT exist.
Can I use this tool to validate form inputs?
Yes! Test regex patterns for form validation like phone numbers, postal codes, credit cards, or custom formats. The visual feedback helps you ensure your validation patterns correctly accept valid inputs and reject invalid ones before implementing them in your application.