Regex Tester

Test JavaScript regular expressions against text, inspect matches and capture groups, and highlight matching results.

Regular Expression

Enter a JavaScript regular expression and choose the flags you need.

//
g = globali = ignore casem = multilines = dotAllu = unicodey = sticky

Flags follow the JavaScript RegExp standard. Supported flags depend on your browser's JavaScript engine.

Test Text

Enter the text you want to test against the regular expression.

0 / 50,000 characters

About Regex Tester

A free online JavaScript regex tester for checking regular expression patterns against sample text. Inspect matching values, character positions and capture groups, and highlight matching text. All evaluation runs locally in your browser.

How to Use the Regex Tester

Use the following steps to test a regular expression:

  1. Enter your regular expression pattern in the Pattern field.
  2. Add one or more JavaScript regex flags if needed.
  3. Enter sample content in the Test Text field.
  4. Select Test Regex to run the expression.
  5. Review the highlighted text, matching values, indexes and capture groups.

Change the pattern, flags or test text and run the test again to compare different expressions.

What Is a Regular Expression?

A regular expression, commonly called regex or regexp, is a sequence of characters that describes a search pattern. It is used to find, match and extract text based on rules rather than searching for one exact string.

For example, the pattern \d+ matches one or more consecutive digits. Regex is commonly used in text processing, input validation, log analysis and data extraction.

This tool uses the JavaScript RegExp engine built into your browser. Its syntax and behavior may differ from regex implementations used by Python, PHP, Java, PCRE and other programming languages.

Common JavaScript Regex Flags

Flags change how a regular expression searches for matches. They are added after the closing slash of a regex pattern.

FlagDescription
gGlobal: find all matching occurrences instead of stopping after the first match.
iIgnore case: match uppercase and lowercase letters without distinguishing between them.
mMultiline: make the ^ and $ anchors work at line boundaries.
sDotAll: allow the dot character to match line terminators.
uUnicode: enable Unicode-aware pattern matching.
ySticky: match only at the position specified by the regular expression's lastIndex.

JavaScript also supports additional flags in modern browsers. The accepted flags depend on the browser's JavaScript engine.

Common Regex Examples

The following examples demonstrate common JavaScript regex patterns. Copy a pattern into the Pattern field and enter suitable sample text to test it.

Find Email-Like Text

[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}

Finds text that resembles an email address. It is not a complete email validation rule.

Numbers Only

^\d+$

Matches a string containing one or more digits only.

Letters Only

^[A-Za-z]+$

Matches one or more English letters without spaces or numbers.

Digits and Letters

^[A-Za-z0-9]+$

Matches a string containing English letters and digits only.

Extract Words

[A-Za-z]+

Finds consecutive sequences of English letters.

Match a Date (YYYY-MM-DD)

^\d{4}-\d{2}-\d{2}$

Checks the date format, but does not verify whether the calendar date is valid.

Regex Character Classes and Quantifiers

Character classes and quantifiers are basic building blocks for writing regular expressions.

SyntaxMeaning
.Matches any character except line terminators by default.
\dMatches an ASCII digit.
\wMatches an ASCII word character.
\sMatches whitespace characters.
[abc]Matches one character from the specified set.
*Matches zero or more repetitions.
+Matches one or more repetitions.
?Matches zero or one repetition.
{n}Matches exactly n repetitions.

What Are Capture Groups?

Capture groups allow part of a regular expression match to be retrieved separately. They are created using parentheses in a pattern.

For example, the pattern (\d{4})-(\d{2})-(\d{2}) matches a date-like string and captures the year, month and day in three separate groups.

This tool displays numbered capture groups for each match. Unmatched optional groups are shown as empty values.

Understanding Match Indexes

Each match includes an index indicating its starting position in the original test text. JavaScript string indexes use UTF-16 code units, so an index may not always equal the number of visible characters when text contains certain Unicode characters such as emoji.

The highlighted text makes it easier to locate matches within the original content.

Regex Matching and Global Search

Without the global or sticky flag, the tester reports the first match returned by JavaScript's regular expression engine. With the global flag, it finds successive non-overlapping matches throughout the test text. The sticky flag attempts matches at successive positions according to the JavaScript lastIndex behavior.

Zero-length matches are also possible. These occur when a pattern matches a position without consuming any characters.

Regex Safety and Performance

Some regular expressions can take a long time to evaluate, especially when patterns contain nested or ambiguous repetition. This is sometimes associated with catastrophic backtracking.

To reduce the impact of expensive expressions, this tool runs regex evaluation inside a separate Web Worker. The main page applies a 500ms timeout and terminates the Worker if the evaluation exceeds that limit.

The tool also limits the number of displayed matches to 1,000. These safeguards help keep the interface responsive, but they do not guarantee that every regular expression will be fast or suitable for production use.

Input Limits

To keep testing manageable in the browser, the tool applies the following limits:

  • Regular expression pattern: up to 1,000 characters.
  • Regex flags: up to 16 characters.
  • Test text: up to 50,000 characters.
  • Displayed matches: up to 1,000 results.
  • Evaluation timeout: 500 milliseconds.

Is My Test Data Uploaded to a Server?

No. Regular expression evaluation takes place locally in your browser using a Web Worker. The pattern and test text are not sent to a KitDevTools server for processing.

Your browser must support JavaScript and Web Workers for this tool to function.

Frequently Asked Questions

Does this tool support Python or PHP regular expressions?

No. This tool uses JavaScript RegExp syntax. Patterns designed for Python, PHP PCRE or other regex engines may need to be adapted before they work here.

Why does my pattern return no matches?

Check the pattern, flags and test text. Anchors such as ^ and $ can restrict where a match is allowed, and case-sensitive matching is enabled unless you use the i flag.

Why are only 1,000 matches displayed?

The tool applies a maximum of 1,000 displayed matches to limit processing and rendering costs. Additional matches are not included in the results.

Can this tool validate email addresses?

It can test patterns that find email-like text, but a regular expression alone cannot guarantee that an address exists or can receive email. Production email validation should include appropriate server-side checks and, where necessary, confirmation by sending an email.

Why did my regex test time out?

The expression may be computationally expensive for the supplied text. Try simplifying nested repetition, reducing ambiguous alternatives or using a shorter test string.

Your privacy matters

We use optional analytics cookies to understand how our tools are used and improve your experience. These controls apply to Google Analytics only, not advertising preferences. Privacy Policy