phacility/phabricator · error · Exception

The following regex is malformed and cannot be used: %s

Error message

The following regex is malformed and cannot be used: %s

What it means

PhabricatorConfigRegexOptionType validates config options whose value is a map of PCRE pattern => specification (used by 'syntax.filemap'). It compiles each pattern key with preg_match($pattern, ''); preg_match returning false means the PCRE pattern is malformed (bad delimiters, unbalanced parens, invalid modifiers) and saving the option is refused.

Source

Thrown at src/applications/config/custom/PhabricatorConfigRegexOptionType.php:10

<?php

class PhabricatorConfigRegexOptionType
  extends PhabricatorConfigJSONOptionType {

  public function validateOption(PhabricatorConfigOption $option, $value) {
    foreach ($value as $pattern => $spec) {
      $ok = preg_match($pattern, '');
      if ($ok === false) {
        throw new Exception(
          pht(
            'The following regex is malformed and cannot be used: %s',
            $pattern));
      }
    }
  }

}

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Wrap every pattern in valid delimiters, e.g. '/\.php$/' or '@\.php$@' (the defaults use '@').
  2. Pre-validate each key compiles: php -r 'var_dump(@preg_match($argv[1], "") === false);' -- '<pattern>'.
  3. Keep modifiers to the valid PCRE set and place them after the closing delimiter.

Example fix

// before (config JSON for syntax.filemap)
{"\.phpt$": "php"}
// after
{"/\.phpt$/": "php"}
Defensive patterns

Strategy: validation

Validate before calling

// Validate every pattern key compiles under PCRE before saving config.
foreach ($value as $pattern => $spec) {
  if (@preg_match($pattern, '') === false) {
    throw new Exception('Pattern will be rejected: '.$pattern);
  }
}

Prevention

When it happens

Trigger: Saving a syntax.filemap value with a pattern missing delimiters, e.g. "\.php$" instead of "/\.php$/"; invalid or misplaced PCRE modifiers; unbalanced brackets or parentheses inside the pattern.

Common situations: Editing syntax.filemap JSON in the config UI; copying regexes from JavaScript/Python documentation where delimiters are not part of the pattern syntax (PCRE requires them).

Understand the failure class

Related errors


AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21). Data as JSON: /api/errors/c5791524a74abd87. Report an issue: GitHub.