Regex Tester: Test Patterns and Highlight Matches

Developer Tools Active

Check JavaScript regular expressions against sample text. See highlighted matches, the match count, and error messages for invalid patterns.

Regex Tester

🧪 Regex Tester

Test, debug, and match regular expressions against sample text with live match highlighting and flags.

🔬 Regular Expression
Match Count
2
Active Flags
gi
Pattern Status
Valid syntax

Rate This Tool

Your feedback helps others discover great tools

–
out of 5
No ratings yet

Tap a star to rate:

About This Tool

Ever written a pattern that matched too much, or nothing at all? A regex tester shows what a regular expression catches before you copy it into code. The Regex Tester on AskWebTools checks a pattern against sample text and highlights each match.

It is built for developers, students, and anyone who writes search or validation rules. Enter a pattern, set optional flags, and paste your text. The tool then shows the match count right away.

Table of Contents

  • What the Regex Tester Does
  • How to Use It, Step by Step
  • How the Matching Formula Works
  • Worked Example
  • How to Read the Results
  • Flags and Common Mistakes
  • Limitations and Assumptions
  • FAQs About the Regex Tester

What the Regex Tester Does

The tool compares one pattern against one block of text. It counts every match, highlights each one, and reports whether the pattern compiles.

  • Regex Pattern: a single-line field for the expression. Type it without surrounding slashes.
  • Flags: a text field for flag letters such as g, i, m, or s.
  • Test Text: a text box for the sample you want to search.
  • Match Count: the number of matches in the text.
  • Active Flags and Pattern Status: show the flags the tool runs and whether the pattern compiles.
  • Evaluate Regex: reruns the test. Results also update on every edit and when you press Enter in the Pattern or Flags field.

How to Use It, Step by Step

  1. Type your expression in the Regex Pattern field, which starts with a sample email pattern.
  2. Enter any flags in the Flags field, which starts with the sample value gi.
  3. Paste your own sample text into the Test Text box, replacing the default.
  4. Check the Match Count and Pattern Status cards in the top row.
  5. Read the highlighted text in the Match Highlights card below the inputs.
  6. Press Evaluate Regex to rerun the test, or keep typing to update the results.

How the Matching Formula Works

The tool builds one JavaScript regular expression from your pattern and flags. It then finds every match in the text you pasted. Each match is then wrapped in a yellow highlight.

Pattern+Flags (g added)→Text search→Match Count
  • RegExp = a new JavaScript regular expression built from Pattern and Flags.
  • Matches = every result returned when the text is searched with RegExp.
  • Match Count = the number of entries in Matches.

The tool adds g when you leave it out, so every match gets listed. Your pattern is read exactly as typed, so a stray space counts as part of it.

Worked Example

Priya wants to find US phone numbers in the 555 format. Her pattern is \b\d{3}-\d{4}\b, and she types the flag g. Her sample text is "Call 555-1234 or 555-9876 after 5 PM."

FieldInput or Result
Regex Pattern\b\d{3}-\d{4}\b
Flagsg
Active Flagsg
Match Count2
Pattern StatusValid syntax
Match Highlights555-1234 and 555-9876

The text 5 PM is not highlighted, because it has no dash between digit groups.

How to Read the Results

  • Match Count: the total number of matches, including zero-width matches. It shows 0 when nothing matches or the pattern cannot run. For example, a* on baaa gives 3, because two empty matches count but show no highlight.
  • Active Flags: the flags the tool runs. An empty field shows g, and flag y shows yg, because the tool appends g.
  • Pattern Status: Valid syntax means the browser accepted the pattern and flags. Invalid Pattern shows the browser error. For the pattern ( with no flags, the text reads Regex Error: Invalid regular expression: /(/: Unterminated group. Other statuses are Invalid Flags, Too Long, Timed Out, and Empty.
  • Match Highlights: your sample text with each non-empty match in a yellow span.
  • Note Box: the box below the inputs explains added flags, sticky matching, zero-width matches, and results with no matches.

A Valid syntax status does not prove the pattern finds the right text. Check both matches and non-matches before you use the pattern.

Flags and Common Mistakes

Flags change how the pattern reads the text in your sample. The tool accepts only the letters d, g, i, m, s, u, v, and y. Uppercase letters are rejected, so an uppercase I triggers Invalid Flags. Typing xyz shows the alert "Unknown flag: x, z. Use d, g, i, m, s, u, v, or y."

  • i matches upper and lower case letters alike.
  • m lets ^ and $ match at each line break.
  • s lets the dot match line breaks too.

Flag y is sticky, so each match must start exactly where the previous match ended. With y, the pattern \d on the text "12 ab 34" returns 2 matches. Without y, the same text returns four matches in total. The note box explains that matching stops at the first gap, and Active Flags reads yg.

Watch for these common mistakes. Typing slashes around a pattern, such as /abc/, makes the slashes literal characters. Leaving a dot unescaped matches any character, so use \. for a real period. The Regex Escape Tool can escape special characters for you.

The Regex Cheat Sheet lists common tokens, and the Regex Generator helps you build a pattern. To swap matches for new text, use the Regex Replace Tester. Explore more developer utilities on the Developer Tools hub.

Limitations and Assumptions

  • The tool uses only the JavaScript regular expression engine. Syntax from Python, PHP, or Java may behave differently.
  • A pattern can be up to 500 characters, and test text up to 20,000 characters. Longer input shows a Too Long status and does not run.
  • The text limit counts UTF-16 code units, which is JavaScript string length, not visible characters.
  • The caps are chosen values, not a published standard.
  • If the browser blocks background workers, matching runs on the page with no time limit, and the note says so.
  • The tool shows matches, not whether a pattern suits your data. Test with both good and bad samples.

FAQs About the Regex Tester

Does the Regex Tester Send My Text to a Server?

The tool does not send your pattern or text to a server, because its code makes no network request. Your text stays in your browser while you work.

Why Does the Default Sample Ignore One Address?

The default email pattern needs a dot followed by at least two letters after the @ sign. In john.doe@com., the final dot has nothing after it, so that address does not match. The pattern is still loose, because a..b@x.io does match.

Why Do Some Patterns Time Out?

Nested repeats, such as (a+)+$, try many paths before they fail. In testing, 30 a characters followed by a b timed out. Shorten the text or simplify the pattern to avoid this.

What Does the Timed Out Status Mean?

Matching runs in a background worker, and the tool stops it after 2 seconds. The status reads Timed Out, Match Count shows 0, and your text appears without highlights. The time limit stops the wait, but it does not make the pattern cheaper.

Can I See Captured Group Values?

No, the output card highlights only the full match for each result. Parentheses still group the pattern, but group values are not listed.

This calculator gives general estimates only and is not professional advice. Reviewed for general accuracy by Prof. Dr. Khalil Mudassar, PhD.

Category: Developer Tools

You May Also Like

View All