Regex Tester Documentation

A complete guide to testing regular expressions, understanding flags and capture groups, and a quick reference of common regex syntax.

Launch the Regex Tester →
On This Page
  1. What This Tool Does
  2. What a Regular Expression Actually Is
  3. Understanding Each Flag
  4. What Capture Groups Are
  5. A Quick Reference of Common Regex Syntax
  6. Step-by-Step: Using the Tool
  7. Why This Tool Uses JavaScript's Native Regex Engine
  8. Privacy and Data Handling
  9. Frequently Asked Questions

What This Tool Does

The Regex Tester lets you write a regular expression pattern and test it live against a sample block of text, instantly highlighting every match directly within the text, while a separate panel lists each match's starting index and any capture groups it contains. Four common flags — global, case-insensitive, multiline, and dot-matches-newline — can be toggled on or off to adjust exactly how the pattern is interpreted.

Because the highlighting and match list update live as you type, this tool is built for the kind of fast, iterative experimentation that writing and debugging regular expressions genuinely requires — adjusting a pattern slightly and immediately seeing how that change affects which parts of the text match, rather than needing to run and re-run a separate script repeatedly.

What a Regular Expression Actually Is

A regular expression (regex) is a specialized pattern-matching language for describing a set of possible text strings using a compact, symbolic syntax, rather than listing out every possible match literally. A single regex pattern can describe something as simple as a literal word, or something as complex as "any string that looks like a valid email address," using a combination of literal characters, special metacharacters, and quantifiers that together define exactly what counts as a match.

Regular expressions are supported, with largely consistent core syntax, across virtually every programming language and many command-line tools, which is part of why they're such a durable, broadly transferable skill: a pattern you write and test here using JavaScript's regex engine will, with only minor syntax differences in some edge cases, generally work the same way in Python, Perl, grep, and countless other tools and languages that implement the same foundational regex concepts.

Understanding Each Flag

Global (g) tells the regex engine to find every match in the text, rather than stopping after the first one. Without this flag, even a pattern that could match multiple times in your test string would only highlight the single first occurrence — this is one of the most common sources of confusion for anyone new to using regex, since forgetting the global flag makes it look like a correct pattern is somehow only partially working.

Case-insensitive (i) makes the pattern match regardless of uppercase or lowercase letters, so a pattern like hello would match "Hello," "HELLO," and "hello" all identically, rather than only the exact-case literal text.

Multiline (m) changes how the ^ and $ anchors behave when your test string spans multiple lines. Without this flag, ^ and $ only match the very beginning and end of the entire string; with it, they also match the beginning and end of each individual line within the string, which matters whenever you need to match patterns that should align with line boundaries rather than only the whole text's absolute start and end.

Dot matches newline (s) changes the behavior of the . metacharacter, which normally matches any single character except a newline. With this flag enabled, . will also match newline characters, which is necessary whenever you need a pattern to span across line breaks in your test string rather than stopping at them.

What Capture Groups Are and Why the Match List Shows Them

Parentheses within a regex pattern create a capture group: a way of marking a specific sub-portion of a match so it can be extracted and referenced separately from the overall match. This is extremely useful when you don't just want to know whether something matched, but specifically want to pull out one particular piece of it — for example, matching an entire phone number but specifically capturing just the area code portion as its own separate, directly accessible value.

This tool's match list panel shows, for every match found, both the full matched text and any capture groups contained within it, which is exactly the information you'd need when writing code that goes on to actually use those captured sub-matches programmatically, letting you confirm your groups are capturing exactly the sub-strings you intend before writing that downstream code.

Worked Example

The pattern (\d{3})-(\d{4}) applied against the text "Call me at 555-1234" would match the full text 555-1234, with capture group 1 containing 555 and capture group 2 containing 1234 — letting you independently access the exchange and the line number portions of the matched phone number fragment.

Step-by-Step: Using the Tool

  1. Enter a regular expression pattern into the Regular Expression field.
  2. Toggle flags as needed: enable Global if you expect multiple matches, Case-insensitive if case shouldn't matter, and the other flags as your specific pattern requires.
  3. Type or paste your test string into the Test String area.
  4. Review the Highlighted Matches, where every matching portion of your test string is visually highlighted directly in place.
  5. Check the Match Index and Capture Groups panel for precise details on exactly what matched and where, plus any capture group contents.

A Quick Reference of Common Regex Syntax

A handful of symbols and constructs cover the overwhelming majority of everyday regex usage, and recognizing them on sight makes reading unfamiliar patterns dramatically easier:

Combining just these building blocks covers an enormous range of practical pattern-matching needs, from validating simple formats like phone numbers or postal codes to extracting specific pieces of structured text from log files or configuration data.

Why This Tool Uses JavaScript's Native Regex Engine

This tool runs patterns through JavaScript's own built-in RegExp engine, the same regex implementation every web browser uses natively, rather than reimplementing regex matching logic from scratch or relying on some separate, potentially inconsistent third-party library. This has two direct, practical benefits: the matching behavior you see here is guaranteed accurate and consistent with how any browser's own JavaScript code would actually behave, and there's no risk of a custom reimplementation introducing subtle bugs or behavioral differences from genuine regex semantics.

It's worth knowing that different regex engines across different programming languages do have some genuine syntax and behavior differences at the edges (certain advanced features, like lookbehind assertions, vary in support across engines, and some languages use slightly different metacharacter conventions). A pattern tested and confirmed working here, using JavaScript's engine, should be understood as validated specifically for JavaScript-based regex usage, though the overwhelming majority of common regex syntax is shared consistently enough across engines that this tool remains broadly useful for general regex experimentation and learning.

Privacy and Data Handling

All pattern matching happens entirely within your browser using the native JavaScript regex engine. No network request of any kind is made by this tool, and neither your pattern nor your test text is ever transmitted anywhere, logged, or stored.

Frequently Asked Questions

Why is only my first match highlighted even though my pattern should match more than once?

This almost always means the Global (g) flag isn't enabled. Without it, JavaScript's regex engine stops after finding the first match, which is standard, well-documented behavior, not a bug in this tool.

Why doesn't my pattern using ^ and $ work the way I expect across multiple lines?

By default, ^ and $ only anchor to the very start and end of the entire test string. Enabling the Multiline (m) flag makes them also match the start and end of each individual line, which is likely what you want if your test string spans multiple lines.

Will a pattern that works here also work in Python or another language?

Most core regex syntax is shared broadly across languages, but some advanced features and minor syntax conventions do differ between regex engines. A pattern confirmed working here is validated specifically against JavaScript's regex engine.

What's the difference between a match and a capture group?

A match is the entire portion of text your pattern found as satisfying the whole expression. A capture group is a specifically marked, smaller sub-portion within that match, defined using parentheses in your pattern, letting you isolate and reference just that piece separately.