Skip to main content

Format a regex

Format Regex arranges a valid pattern into readable groups and lines. It formats regions where free-spacing mode is active.

Free
Unavailable
Pro
Included
Self-hosted
Included
Compare plans

Format the current pattern​

  1. Select the engine for your application.
  2. Resolve any pattern errors.
  3. Verify that the intended region uses free-spacing mode.
  4. Select Format Regex in the tools menu.
  5. Review the output with your existing positive and negative inputs.

The formatter does not enable free-spacing mode for you. Whitespace and # can change meaning in this mode, depending on the engine and context.

Before and after​

Use PCRE2 (PHP) with no external flags. The inline (?x) enables free-spacing mode.

Before:

(?x)^(?:ORD|INV)-[0-9]{4}$

With an indentation width of 2 and a maximum line width of 40, the formatter produces:

(?x)
^ (?:ORD | INV) -[0-9]{4}$

Both versions accept ORD-0042 and INV-0187. Both reject ORD-42, INV-01870, XORD-0042, and an empty string.

Free-spacing scope​

PCRE, PCRE2, Python, Java, .NET, and Rust support formatter workflows with compatible free-spacing syntax. Engine differences still apply.

A pattern can enable free spacing for only part of its text. The formatter leaves other regions unchanged.

Literal spaces, escaped characters, character classes, and comments need particular care. Reusing formatted text in another engine requires a new correctness check.

Configuration​

Open Settings > Editor > Conversion & output to change the indentation and line width.

The current line-width control accepts 40 to 160 characters. Indentation choices are 2, 4, or 8 spaces. A long indivisible construct can exceed the preferred width.

If formatting does not change the pattern​

Message or resultNext action
Pattern errorsResolve the errors shown in the editor.
No free-spacing regionUse the selected engine's free-spacing syntax only where you intend its behavior.
Already formattedContinue with the existing output.
Cannot format right nowRetry after the application finishes loading. If the problem continues, use application troubleshooting.