Skip to main content

Step through a regex

The Regex Debugger shows how PCRE2 matches a pattern. Select a block to inspect its input position and captures.

Free
Unavailable
Pro
Included (PCRE2)
Self-hosted
Optional add-on
Compare plans

Open the debugger​

  1. Select PCRE2 (PHP).
  2. Enter a valid pattern and a nonempty test string.
  3. Open Regex Debugger from the tools menu.

You can also open the debugger from an individual unit test.

Move through the trace​

The graph shows match attempts from left to right, with nested groups underneath. Each attempt tries the pattern at an input position.

Click a block to select it. Click it again to clear the selection.

Mod means Cmd on Mac and Ctrl on Windows or Linux.

ControlShortcutAction
Graph inspectionLeft / RightSelect a block at the same depth within the current attempt.
Graph inspectionUp / DownSelect the parent / first child.
StepMod+Left / Mod+RightFollow execution, including group results.
OperationShift+Left / Shift+RightMove between operations without stopping at enclosing group results.
Match—Move to the first operation in the previous or next successful attempt.
Failure—Move to the first operation in the previous or next failed attempt.

Step visits each group result after its operations. Operation avoids these extra stops in nested assertions and recursive patterns. Both stop at each attempt result before continuing to another attempt.

After you click a group or attempt, the next Step or Operation button enters its first operation.

Navigation buttons focus the graph so you can continue with the keyboard. Hold Mod to show shortcuts on the Step and Operation buttons. The keyboard button beside Help opens shortcut help.

Read the input and captures​

The Input and captures panel shows the selected block's input positions, captures, and step range. Highlights distinguish consumed text, assertion checks, and text given back during backtracking.

Inside assertions, the main cursor stays at the outermost assertion's starting position. A dotted marker shows the assertion's position when it differs from the main cursor.

Adjust the view​

Use the mouse wheel or overview handles to zoom. Drag the graph to pan. Reset zoom restores the full trace width and returns to the top.

Pattern and Input switch the text shown on graph blocks.

Inspect backtracking​

Use this pattern with no flags:

^(?<key>.+)=(?<value>[0-9]+)$

Input:

timeout=120

Open in regex101

  1. Open Regex Debugger and select the first .+ operation.
  2. Select Next regex operation in the Operation controls.
  3. Continue through the operations until Match found appears.

The greedy .+ first consumes all 11 characters, so = fails. Backtracking gives characters back until = matches the separator. The final captures are key: timeout and value: 120.

Backtracking example in an earlier debugger interface.

Recording limits​

The initial limit is 10,000 events. When this limit stops the trace, Record more doubles it, up to 1,000,000 events.

Incomplete trace means a recording limit stopped the trace. A capture limit can also stop recording without a Record more option. Execution stops after 30 seconds.

Trace length does not measure production performance.