Regex Tester

The Regex Tester lets you write, test, and debug regular expressions in real-time with match highlighting and capture group display. Essential for text processing.

Free online tool · Developer Tools · No installation · No sign-up required

Overview

A regular expression, or regex, is a powerful tool for pattern matching in text. It provides a concise and flexible means for identifying strings of text, such as particular characters, words, or patterns of characters. However, crafting the perfect regex can be a complex and often frustrating task. This is where a regex tester becomes an indispensable utility for developers, data scientists, and anyone working with text data. It provides an interactive environment to build, test, and debug regular expressions in real-time, transforming a potentially time-consuming process into an efficient and intuitive one. By allowing users to see matches as they type, a regex tester demystifies the intricate syntax of regular expressions and helps prevent errors in production code.

Technically, a regex tester operates by taking a user-provided regular expression pattern and a sample text string as input. It then applies the regex engine to the text, highlighting all the substrings that match the pattern. Advanced testers support various “flavors” of regex, such as PCRE (used in PHP and other languages), JavaScript, Python, and Go, which is crucial because the syntax and supported features can vary slightly between them. These tools often include features like syntax highlighting for the regex pattern, detailed explanations of what each part of the expression does, and information about match groups. This immediate feedback loop is what makes regex testers so powerful for both beginners and experts.

The primary benefit of using a regex tester is the significant boost in productivity and accuracy it offers. Instead of a trial-and-error approach within a codebase, developers can iteratively build and refine complex patterns with instant visual feedback. This not only saves time but also helps in crafting more robust and efficient expressions. For students and those new to regex, a tester serves as an invaluable learning tool, providing a hands-on way to understand the impact of different tokens and structures. Furthermore, many online regex testers offer a library of community-contributed patterns, providing solutions to common problems and showcasing advanced techniques, fostering a collaborative learning environment.

Worked example

Two valid addresses out of three, with named groups

A signup form validates an email field and the developer wants to see which of three pasted lines match and what the local part and the domain of each one are.

  1. Enter the pattern ^(?<user>[A-Za-z0-9._%+-]+)@(?<domain>[A-Za-z0-9.-]+\.[A-Za-z]{2,})$ and switch on the g, i and m flags. The m flag is what makes the anchors apply to each line.
  2. Paste three lines: ana.silva@example.com, not-an-email, pedro@empresa.com.br.
  3. The matcher reports 2 matches. The first is ana.silva@example.com at index 0 with user ana.silva and domain example.com, and the second is pedro@empresa.com.br at index 35 with user pedro and domain empresa.com.br.
  4. The middle line produces no match, which is the point of testing a rejection case as well: a pattern that matches everything is not a validator.
  5. The Matches panel lists each match with its index, its numbered groups and its named groups, and a zero-length match is labelled as such instead of being drawn as an empty highlight.
  6. Switch to Replace mode and use a substitution with $1 and $2 to rewrite the matched text. Without the g flag the replacement would only touch the first occurrence.

Result: The pattern accepts two of the three lines and the named groups hand back the local part and the domain directly, so the form logic can read a named group instead of splitting on the at sign. Nothing was validated semantically: the pattern still accepts addresses that do not exist.

How to use Regex Tester

  1. Enter regex pattern
  2. Paste test text
  3. See matches highlighted
  4. View capture groups

Common mistakes

Leaving the g flag off and concluding that the pattern matches only once.

Without g the engine stops at the first match, which is correct JavaScript behaviour. Turn g on to list every match, and remember that y (sticky) matches only at the current position, which is a different tool for a different job.

Testing a pattern that can backtrack catastrophically.

There is no timeout and no worker: the expression runs on the page thread, so a nested quantifier such as (a+)+$ against a long run of a characters can freeze the tab. Prefer specific quantifiers, character classes and anchors, and time the pattern in a console before shipping it.

Treating a match count as proof that the pattern is correct.

The tester reports syntax errors and matches, nothing more. Always include at least one string that must be rejected, the way the middle line above is included, because a pattern that matches everything looks perfect against a list of valid examples.

Pasting a pattern with slashes, such as /abc/gi, and expecting the slashes to be part of the expression.

A pasted literal is parsed and its flags are applied for you, which the hint under the field states. The same slashes inside a longer string are not special, so keep the expression in the pattern box and set the flags with the buttons.

Features

Limits worth knowing

When to use it

Practical tips

Why use this tool

When this is not the right tool

Frequently asked questions

What is regex?

Patterns for matching character combinations in strings.

Which flavor?

JavaScript regex engine.

Capture groups?

Parentheses create groups capturing matched text.

Common patterns?

Email, phone, URL patterns available as references.

Related tools in Developer Tools

Further reading

Regex Tester: Test Regular Expressions Online

Test and debug regular expressions with real-time matching, highlighting, and explanation. Supports JavaScript regex syntax.