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
- Wrap every pattern in valid delimiters, e.g. '/\.php$/' or '@\.php$@' (the defaults use '@').
- Pre-validate each key compiles: php -r 'var_dump(@preg_match($argv[1], "") === false);' -- '<pattern>'.
- 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
- Always include PCRE delimiters around patterns ('/.../' or '@...@'), unlike JS/Python regex literals.
- Test candidate patterns with php -r 'var_dump(preg_match("/your\\.pattern/", ""));' first.
- Model new syntax.filemap entries on the shipped defaults, which use '@' delimiters.
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
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- The regular expression "%s" is not valid. Regular expression
- The first regexp in the regexp pair, "%s", is not a valid re
- The second regexp in the regexp pair, "%s", is not a valid r
- Search cluster configuration is not valid: each entry in the
- Search engine configuration has an invalid service specifica
AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21).
Data as JSON: /api/errors/c5791524a74abd87.
Report an issue: GitHub.