Regex Tester
Test regular expressions live, highlight matches, inspect capture groups, and understand pattern tokens faster.
Match Preview
Matches
Pattern Explanation (quick)
About Regex Tester Online โ Test Regular Expressions Live
This free regex tester online lets you write, test, and debug regular expressions interactively with real-time match highlighting. Type your pattern, set flags, and paste your test string โ matches are highlighted instantly in the text and listed below with their exact character positions and capture group values. Whether you are learning regular expressions for the first time, debugging a complex validation pattern, or verifying that a substitution regex works correctly, this regex tester makes the process immediate and visual.
Regular expressions (regex or regexp) are a domain-specific language for describing text patterns. They appear in virtually every programming language โ JavaScript, Python, Java, Ruby, Go, PHP, Perl โ and in command-line tools like grep, sed, and awk. Regex patterns are used for input validation (email addresses, phone numbers, postal codes), data extraction from unstructured text, search-and-replace operations in code editors, log file parsing, URL routing in web frameworks, and text transformation pipelines. The core concepts โ character classes, quantifiers, anchors, groups โ are transferable across languages, even when specific syntax details differ between regex engines.
How to Use the Regex Tester
- Enter your regex pattern in the pattern field. Do not include surrounding slashes โ type just the pattern itself (e.g.
\b\d{4}\bnot/\b\d{4}\b/g). - Set any flags using the flag checkboxes or input:
g(global โ find all matches, not just the first),i(case-insensitive),m(multiline โ^and$match line starts and ends). - Type or paste your test string in the text area. Matches are highlighted in real time as you type in either field.
- The match list below shows each match with its start position, end position, the matched text, and any capture group values.
How the Regex Testing Works
The tool uses JavaScript's built-in RegExp object to compile your pattern with the specified flags and execute it against your test string. Match positions and capture groups are extracted from the result and used to inject highlight spans into the rendered test string display. The tester updates on every keystroke using JavaScript event listeners โ there is no form submission or server round-trip involved. All pattern execution happens in your browser tab.
Example Patterns
4-digit numbers: Pattern \b\d{4}\b with flag g โ matches "1234" and "5678" in "Call 1234 or 5678 but not 123 or 12345"
Email addresses: [a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,} with flag gi
HTML tags: <[^>]+> with flag g
Tips for Writing and Testing Regular Expressions
- Always use the
g(global) flag when looking for multiple matches: Without the global flag, JavaScript regex stops after the first match. If your test string has multiple instances of your pattern and you only see one match highlighted, add thegflag. This is the most common reason beginners see fewer matches than expected โ the flag is required to find all occurrences. - Use capturing groups to extract specific parts: Wrap the part of your pattern you want to extract in parentheses to create a capturing group. For example,
(\d{4})-(\d{2})-(\d{2})matches a date like "2024-03-15" and captures the year, month, and day as separate groups (group 1, 2, and 3). The match list in the regex tester shows each capture group's value separately, making it easy to verify what each group captures. - Use
\bword boundaries to avoid partial matches: The pattern\d+matches digits anywhere โ including within longer numbers. To match only standalone numbers (not parts of longer ones), wrap with word boundaries:\b\d+\b. Word boundary\bmatches the position between a word character (letter, digit, underscore) and a non-word character, preventing matches inside longer strings. - Use non-capturing groups
(?:...)for grouping without extraction: If you need to group part of a pattern for quantification or alternation but do not want to capture it as a group, use(?:...)instead of(...). For example,(?:https?://)matches "http://" or "https://" as a unit for quantification without creating a capture group that appears in the match results. - Test edge cases explicitly: A regex that works on your intended input may also match unintended strings. After writing a pattern, test it against inputs it should NOT match to verify it does not produce false positives. For email validation, test malformed addresses like "user@", "@domain.com", and "user@domain" alongside valid ones. Iteratively tighten the pattern based on the edge cases you discover.
Frequently Asked Questions about Regex Tester Online
u flag.g (global) flag, JavaScript's regex engine stops after finding the first match and returns only that result. To find all matches in your test string, add the g flag using the flag input field. This is the most common source of confusion when testing regex patterns โ the absence of the global flag is not an error, but it limits the match to the first occurrence. The g flag must be combined with exec() in a loop or used with matchAll() in code; this tester handles that automatically when the flag is set.. * + ? ^ $ { } [ ] | ( ) \. Examples: to match a literal dot use \. (without escaping, . matches any character); to match a literal opening bracket use \[; to match a literal backslash use \\; to match a literal dollar sign use \$. If you see unexpected matches, check whether unescaped special characters in your pattern are being interpreted as regex metacharacters rather than literals.m (multiline) flag to make the ^ and $ anchors match the start and end of each individual line rather than the start and end of the entire string. Without the m flag, ^ matches only the very beginning of the input and $ matches only the very end. With m, ^pattern matches "pattern" at the start of any line. Paste multiline text into the test string area and use ^/$ anchors with the m flag to test line-anchored patterns.(...) that extract specific sub-portions of the matched text. For example, the pattern (\d{4})-(\d{2})-(\d{2}) matches a date like "2024-03-15" and captures three groups: group 1 = "2024" (year), group 2 = "03" (month), group 3 = "15" (day). The regex tester shows each capture group's value in the match list. In code, capture groups allow you to extract and reuse parts of a match during search-and-replace operations โ for example, rearranging date formats by referencing $1, $2, $3 in the replacement string.*, +, {n,m}) match as many characters as possible while still allowing the overall pattern to match. Lazy (non-greedy) quantifiers (*?, +?, {n,m}?) match as few characters as possible. The difference matters when there are multiple possible match boundaries. For example, with input "<b>bold</b> and <i>italic</i>", the greedy pattern <.+> matches the entire string from the first < to the last > as one match. The lazy pattern <.+?> matches each individual HTML tag separately. Test both versions in this regex tester to see the difference visually.(?=...), negative lookaheads (?!...), positive lookbehinds (?<=...), and negative lookbehinds (?<!...). Lookbehind support requires ES2018 or later, which is supported in Chrome 62+, Firefox 78+, Safari 16.4+, and all recent browsers. Lookaheads and lookbehinds are zero-width assertions โ they match a position in the string based on what comes before or after, without consuming characters in the match. For example, \d+(?= dollars) matches a number only when followed by " dollars" without including " dollars" in the match result.