Regex Lab

Test regular expressions online with match highlighting, capture groups and pattern presets. Inspect JavaScript regex behavior in PSDevTool.

The interactive workspace opens with JavaScript.

Read the tool guide ↓
TOOL GUIDE

Regex Tester & Capture Group Inspector

Check a regular expression against representative text before using it in code. Regex Lab highlights matches and exposes groups so you can understand what the pattern captures.

What you can do

  • Validate pattern syntax and inspect highlighted matches.
  • Review capture groups and matching details.
  • Start with presets and adjust the pattern and flags.

How to use Regex Lab

  1. Enter a pattern and choose the relevant flags.
  2. Paste sample text, including matching and non-matching cases.
  3. Inspect highlighted matches and capture groups, then refine the pattern.

PRACTICAL WALKTHROUGH

Extract an order number from sample text

Build a pattern against small representative examples before using it on a whole log. Include both a string that should match and one that should not, and inspect captured groups rather than checking only whether some match exists.

Example input or setup

Pattern: order-(\d+)
Flags: g
Text: order-42 and order-105; order-x

Expected result

The full matches are order-42 and order-105. Capture group 1 contains 42 and 105. order-x does not match.

The numeric group accepts one or more digits; it does not accept letters. If only a whole field is valid, anchor the pattern to the start and end of that field. The global flag searches for multiple matches and changes how many results you inspect.

Before you rely on the result

  • Patterns use the browser’s JavaScript regular-expression behavior; another language or engine can differ.
  • A pattern that matches the samples is not proof that it handles every valid or malicious input.
  • Backtracking patterns can be expensive. Avoid testing an untrusted complex pattern against an enormous input, and review any risk feedback.

Common questions

Will a pattern behave identically in every language?

Not necessarily. Regex engines differ. This browser tool tests JavaScript regex behavior, so check the target language’s rules before copying a pattern.

Why does a pattern match more than expected?

Check flags, greedy quantifiers, anchors and your test text. Capture-group output can help reveal which section of the pattern consumed the text.

← All developer tools