Skip to content

Developer Tools

Regex Tester

See exactly what your pattern matches, with matched text highlighted directly in the sample.

  • Free
  • No sign-up
  • Runs in your browser

Guide

What a regular expression actually is

A regular expression (regex) is a compact pattern language for describing text to match. Rather than searching for one exact string, a regex can describe a shape of text: "a sequence of digits," "an email-like pattern," "anything that starts with a capital letter." This makes regex powerful for validation, extraction, and find-and-replace operations that would otherwise require writing custom logic character by character.

The tradeoff is that regex syntax is dense and easy to get subtly wrong, a pattern that seems to work on your test cases can fail on edge cases you didn't think to try, which is exactly why testing a pattern against varied sample text before using it in production code matters.

How to use this regex tester

  1. Enter your pattern in the pattern field. No need to include the surrounding slashes, just the pattern itself.
  2. Set any flags you need, like g for matching all occurrences rather than just the first, or i for case-insensitive matching.
  3. Paste or type sample text into the test area.
  4. Matches are highlighted directly in the text, and the match count updates live as you adjust the pattern.
  5. If the pattern is invalid, an error message explains what's wrong rather than silently failing.

Testing happens entirely in your browser using JavaScript's native regex engine. The same engine your pattern will actually run against if you're using it in JavaScript code.

Common regex patterns and what they do

\d+ matches one or more digits in a row, useful for finding numbers embedded in text. \b[A-Z][a-z]+\b matches whole words that start with a capital letter followed by lowercase letters, a rough (not perfect) way to find capitalized words like proper nouns. ^\s*$ matches a line that's empty or contains only whitespace, useful for detecting blank lines.

A genuinely reliable email-matching regex is more complex than most people expect, because the technical specification for valid email addresses allows for far more variation than typical examples suggest. For anything where correctness truly matters (like validating user input before sending an email), a well-tested existing pattern or a dedicated validation library is usually safer than writing one from scratch.

Why testing against varied examples matters

A pattern that correctly matches your first few test cases can still have blind spots, for instance, a phone number pattern built only against a specific formatting style might fail on numbers with different spacing, dashes, or country codes. Before relying on a pattern in real code, it's worth testing it against the messiest, most varied realistic inputs you can think of, not just the clean examples that come to mind first.

It's equally useful to test what a pattern shouldn't match. Confirming it correctly rejects invalid input is just as important as confirming it accepts valid input, especially for anything used in validation.

Frequently asked questions

What does the 'g' flag do?

It makes the pattern match every occurrence in the text rather than stopping after the first match. Essential when you're counting or extracting multiple matches, not just checking whether one exists.

Why is my pattern not matching anything?

Common causes include forgetting to escape special characters that need to be treated literally (like a period, which normally matches any character), or a case mismatch when the 'i' flag isn't set. Testing incrementally, starting simple and adding complexity, usually isolates the issue quickly.

Is regex the same across all programming languages?

Mostly similar, but not identical. Different languages and engines support slightly different syntax and features. A pattern tested here (using JavaScript's regex engine) should work in JavaScript, but may need minor adjustments in other languages.