Regex Tester preview

Regex Tester

Write regular expressions and see matches highlighted in real time against your test text. Uses a JavaScript regex engine compatible with most modern programming languages.

Key features

  • Real-time match highlighting as you type
  • Group capture and match index details
  • JavaScript regex engine compatible with most languages
  • Error messages for invalid patterns

Guide

Regular expressions are a pattern matching language used in every major programming language, text editor, command-line tool, and database system. They let you search, match, extract, and replace text based on patterns rather than fixed strings. A regex tester gives you a sandbox to write and debug patterns with instant visual feedback on what matches and what does not. This tool lets you type a regular expression and a test string, then see matches highlighted in real-time. You get capture group details, match indices, and flag options. It runs entirely in your browser using JavaScript's RegExp engine. ## How Regular Expressions Work A regular expression defines a search pattern as a sequence of characters and metacharacters. The simplest regex is a literal string: the pattern hello matches the text "hello" exactly wherever it appears. The power comes from special characters (metacharacters) that represent classes, quantities, positions, and groups. Character classes match categories of characters. A dot (.) matches any single character except a newline. \d matches any digit (0-9). \w matches any word character (letters, digits, underscore). \s matches any whitespace (space, tab, newline, carriage return). \D, \W, and \S are the negated versions (non-digit, non-word, non-whitespace). Custom character classes use square brackets: [aeiou] matches any vowel, [a-z] matches any lowercase letter, [^0-9] matches any non-digit character. Quantifiers control how many times a pattern repeats. * means zero or more, + means one or more, ? means zero or one, {n} means exactly n times, {n,} means n or more, and {n,m} means between n and m times. For example, \d+ matches one or more consecutive digits, [a-z]{3,5} matches 3 to 5 lowercase letters, and colou?r matches both color and colour. Anchors match positions rather than characters. ^ matches the start of a string (or line in multiline mode), and $ matches the end. \b matches a word boundary (the position between a word character and a non-word character). These are essential for ensuring your pattern matches at the right position and does not capture partial matches from longer strings. Groups and captures use parentheses. (abc) creates a capturing group that matches "abc" and remembers the matched text. (?:abc) is a non-capturing group that matches but does not remember. (?<name>abc) is a named capturing group. Backreferences like \1 refer to the first captured group's value. Alternation uses the pipe character: cat|dog matches either "cat" or "dog". ## Using the Regex Tester Type your pattern in the regex input field and your test text below it. Matches are highlighted instantly as you type. The tool shows: - All matches in the test string, highlighted with distinct colors - Capture group values for each match, showing what each parenthesized group captured - The match index (starting position in the string) for every match - A flag selector for g (global), i (case-insensitive), m (multiline), s (dotAll), and u (Unicode) Start with the global (g) flag enabled to see all matches, not just the first one. Add the i flag when case does not matter. Use the m flag when your test text has multiple lines and you want ^ and $ to match line starts/ends rather than string start/end. Enable the s flag if you need dot (.) to match newline characters. The u flag enables full Unicode matching, which is important for matching emoji and characters outside the Basic Multilingual Plane. The instant feedback loop is what makes a regex tester valuable. Instead of writing a pattern, running a script, checking the output, editing the pattern, and repeating, you see results in real-time as you modify the pattern or the test text. ## Practical Patterns You Will Use Often Email validation (simplified): [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} matches most email addresses. This is not RFC 5322 compliant (almost no regex is, because the RFC allows quoted strings, comments, and other rarely-used syntax), but it works for form validation where you want to catch obvious typos. For strict validation, send a confirmation email. URL matching: https?:\/\/[^\s]+ matches HTTP and HTTPS URLs. For more precision, use https?:\/\/[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(\/[^\s]*)? to require a valid domain name. For extracting URLs from text that might contain trailing punctuation, use https?:\/\/[^\s.,;:!?)\]]+. IPv4 address: \b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b matches patterns that look like IP addresses. Note that this also matches invalid values like 999.999.999.999. For strict validation that only matches valid octets (0-255), use \b(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\b. Date in YYYY-MM-DD format: \d{4}-\d{2}-\d{2} matches the pattern. To capture parts: (\d{4})-(\d{2})-(\d{2}) gives you year, month, and day in groups 1, 2, and 3. To match only valid months and days, add range checks: (\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]). Hex color code: #([0-9a-fA-F]{3}|[0-9a-fA-F]{6})\b matches both 3-digit and 6-digit hex colors like #FFF and #3a7bd5. Phone numbers (US): \(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4} matches formats like (555) 123-4567, 555-123-4567, and 5551234567. HTML tag extraction: <(\w+)[^>]*>(.*?)<\/\1> matches paired opening and closing tags and captures the tag name (group 1) and content (group 2). This is fine for simple extraction but not for parsing arbitrary HTML. Nested tags, self-closing tags, and attributes with > characters can break this pattern. Use a DOM parser for complex HTML. Log line parsing: (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) \[(\w+)\] (.+) captures timestamp (group 1), log level (group 2), and message (group 3) from log lines like 2026-03-21 14:30:00 [ERROR] Connection refused. CSV field extraction: (?:^|,)("(?:[^"]|"")*"|[^,]*) handles both quoted and unquoted CSV fields, including fields that contain commas within quotes. ## Capture Groups and Extraction Capture groups are one of the most powerful regex features. They let you extract specific parts of a match. In the regex (\w+)@(\w+)\.(\w+) applied to alice@example.com, group 0 is the full match alice@example.com, group 1 is alice, group 2 is example, and group 3 is com. Named groups make patterns more readable and maintainable. Instead of (\d{4}), write (?<year>\d{4}). In JavaScript, the match object includes a .groups property: match.groups.year returns the year value. This is especially useful when your pattern has many capture groups and referring to them by number becomes confusing. Non-capturing groups (?:...) are useful when you need grouping for alternation or quantification but do not need to capture the match. For example, (?:https?|ftp):\/\/ groups the protocol alternatives without creating a capture group. This keeps your group numbering clean and is slightly more efficient. The tester displays all capture groups for each match, making it easy to verify that your groups are capturing the right parts of the text. This is especially useful when building patterns for log parsing, data extraction, or search-and-replace operations where the replacement references captured groups. Backreferences let you match the same text that was captured earlier. The pattern (["']).*?\1 matches a string enclosed in matching quotes (either single or double). The \1 refers to whatever the first group captured, so if the opening quote was \

Frequently asked questions

Which language does it use?

It uses a JavaScript regex engine, compatible with most modern programming languages.

Does it support complex patterns?

Yes. It handles lookaheads, lookbehinds, named groups, and other advanced patterns.

Related guides

Related WebRecast sections