WW Tools

Regex Tester

Test, replace, and explain regular expressions with live highlighting and named groups.

//g
Flags:
0 / 100,000
Enter a pattern and test string to see matches

About Regex Tester

Regular expressions (regex or regexp) are a formal language for describing patterns in text. Rooted in automata theory and formal language theory developed by mathematician Stephen Kleene in the 1950s, regular expressions were first implemented in computing by Ken Thompson in the QED text editor and later in grep, the Unix search utility whose name stands for 'globally search for a regular expression and print matching lines.' Today, virtually every programming language, text editor, and command-line tool supports regular expressions, making them one of the most universally applicable skills a developer can learn.

A regular expression is a sequence of characters that defines a search pattern. Simple patterns are literal strings: the regex 'cat' matches the substring 'cat' in any text. The real power comes from metacharacters and quantifiers: the dot (.) matches any single character, the asterisk (*) means 'zero or more of the preceding element,' the plus (+) means 'one or more,' the question mark (?) means 'zero or one,' square brackets ([abc]) define a character class, parentheses create capture groups, and anchors (^ and $) match the start and end of a line. These building blocks combine to express remarkably sophisticated patterns. For example, the pattern ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ describes the general structure of an email address. Flags modify the behavior of the entire expression: the global flag (g) finds all matches rather than stopping at the first, the case-insensitive flag (i) ignores letter case, the multiline flag (m) makes ^ and $ match line boundaries rather than the start and end of the entire string, and the dotall flag (s) makes the dot match newline characters.

This tool provides a live regex testing environment where you can write a pattern, supply test text, and instantly see all matches highlighted in context. Capture groups are extracted and displayed separately, making it easy to verify that your groups capture exactly the right substrings. You can also use the replace mode to test substitution patterns with backreferences ($1, $2, etc.), which is essential for search-and-replace operations in code editors and build scripts. The tool supports the full JavaScript regex syntax and runs entirely in your browser.

How to Use the Regex Tester

  1. Enter your regular expression in the pattern field at the top of the tool. The pattern is automatically compiled as you type, and syntax errors are shown immediately with a descriptive message.
  2. Set the regex flags using the flag toggles: 'g' for global (find all matches), 'i' for case-insensitive, 'm' for multiline (^ and $ match line boundaries), and 's' for dotall (. matches newlines). The most common combination is 'g' for finding all matches.
  3. Paste or type your test text into the input area below the pattern field. This is the text that the regex will be tested against.
  4. Matches are highlighted in real time within the test text as you type the pattern or modify the input. Each match is visually distinct, making it easy to verify that the pattern matches exactly what you intend.
  5. If your pattern contains capture groups (parentheses), the captured substrings for each match are displayed in a separate panel. This lets you verify that each group captures the correct portion of the match.
  6. Switch to replace mode to test substitution patterns. Enter a replacement string using backreferences like $1, $2 (referring to capture groups) or $& (the entire match) and see the transformed output in real time.
  7. Use the quick reference panel to look up regex syntax, metacharacters, quantifiers, and character classes without leaving the tool.

Common Use Cases

Validating Input Formats

Regular expressions are the standard approach for validating that user input conforms to an expected format: email addresses, phone numbers, postal codes, IP addresses, dates, credit card numbers, and more. While regex validation should always be complemented by server-side validation and, where applicable, format-specific libraries, regex provides a fast first-pass check that catches the majority of malformed inputs before they reach your backend.

Extracting Data from Unstructured Text

When working with log files, HTML content, CSV data, or API responses that do not have a clean structured format, regex is often the fastest way to extract specific pieces of information. For example, extracting all IP addresses from a server log, pulling timestamps from chat transcripts, or finding all URLs in a block of text. Capture groups let you isolate exactly the substrings you need.

Search and Replace in Codebases

Modern code editors and IDEs support regex-based search and replace, which is invaluable for large-scale refactoring. Renaming a function across hundreds of files, converting one date format to another, restructuring import statements, or migrating API call patterns can often be accomplished with a single well-crafted regex replacement. Testing the pattern in this tool first ensures accuracy before applying it across your entire codebase.

Parsing and Transforming Log Files

Operations and DevOps teams frequently use regular expressions to parse application logs, extract structured fields (timestamp, log level, message, request ID), and transform them for ingestion into monitoring systems. Tools like Logstash, Fluentd, and CloudWatch Logs Insights rely heavily on regex patterns for log parsing. Developing and testing these patterns interactively saves significant debugging time.

Frequently Asked Questions

What is the difference between greedy and lazy quantifiers?

By default, quantifiers (*, +, ?) are greedy: they match as much text as possible while still allowing the overall pattern to succeed. For example, the pattern '<.+>' applied to '<b>bold</b>' greedily matches the entire string '<b>bold</b>' because .+ consumes as many characters as it can. Adding a question mark after the quantifier makes it lazy: '<.+?>' matches '<b>' first, then '</b>' separately, because .+? matches as few characters as possible. Use lazy quantifiers when you want the shortest possible match, which is common when parsing delimited content like HTML tags, quoted strings, or bracketed expressions.

What are capture groups and how do I use them?

Capture groups are portions of a regex enclosed in parentheses. They serve two purposes: grouping (to apply quantifiers or alternation to a sub-pattern) and capturing (to extract the matched substring for later use). In the pattern '(\d{4})-(\d{2})-(\d{2})', the three capture groups extract the year, month, and day from a date string. In replacement strings, you reference captures with $1, $2, $3, etc. Non-capturing groups (?:...) provide grouping without capturing, which is useful when you need grouping for syntax but do not need the matched text.

Why does my regex work in one language but not another?

Regular expression implementations vary between languages and engines. JavaScript does not support lookbehind assertions in older engines (though modern engines do), PCRE (used by PHP and many tools) supports features like recursive patterns that JavaScript lacks, and Python's re module has subtle differences from both. This tool uses the JavaScript regex engine, which is the standard for web development. If you are writing regex for a different language, be aware of syntax differences, especially around Unicode support, named groups, and advanced features like atomic groups and possessive quantifiers.

How do I match special characters literally?

Characters that have special meaning in regex -- such as . * + ? ^ $ { } [ ] ( ) | \ / -- must be escaped with a backslash to match them literally. For example, to match a literal period, use \. instead of . (which matches any character). To match a literal backslash, use \\. Inside a character class ([...]), most special characters lose their special meaning, but ] and \ still need escaping, and ^ has special meaning only at the beginning of the class. A common mistake is forgetting to escape these characters, which causes the regex to match far more text than intended.

What are lookahead and lookbehind assertions?

Lookahead and lookbehind are zero-width assertions that check whether a pattern exists ahead of or behind the current position without including it in the match. Positive lookahead (?=...) asserts that what follows matches the pattern. Negative lookahead (?!...) asserts that what follows does not match. Positive lookbehind (?<=...) asserts that what precedes matches. Negative lookbehind (?<!...) asserts that what precedes does not match. For example, '\d+(?= dollars)' matches a number only if it is followed by ' dollars', but the word 'dollars' is not part of the match. These are powerful for matching text based on context without consuming the context itself.

Can regular expressions match nested structures like balanced parentheses?

Standard regular expressions cannot match arbitrarily nested structures because they are equivalent to finite automata, which cannot count nesting depth. This is a fundamental limitation from formal language theory -- balanced parentheses form a context-free language, which requires a pushdown automaton (essentially, a stack). Some regex engines like PCRE and .NET support recursive patterns and balancing groups that extend beyond formal regular expressions, but JavaScript's regex engine does not support these features. For parsing nested structures, use a proper parser or iterative approach instead of regex.