{"record":{"id":"c5791524a74abd87","repo":"phacility/phabricator","slug":"the-following-regex-is-malformed-and-cannot-be-use","errorCode":null,"errorMessage":"The following regex is malformed and cannot be used: %s","messagePattern":"The following regex is malformed and cannot be used: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/applications/config/custom/PhabricatorConfigRegexOptionType.php","lineNumber":10,"sourceCode":"<?php\n\nclass PhabricatorConfigRegexOptionType\n  extends PhabricatorConfigJSONOptionType {\n\n  public function validateOption(PhabricatorConfigOption $option, $value) {\n    foreach ($value as $pattern => $spec) {\n      $ok = preg_match($pattern, '');\n      if ($ok === false) {\n        throw new Exception(\n          pht(\n            'The following regex is malformed and cannot be used: %s',\n            $pattern));\n      }\n    }\n  }\n\n}\n","sourceCodeStart":1,"sourceCodeEnd":19,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/config/custom/PhabricatorConfigRegexOptionType.php#L1-L19","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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."],"exampleFix":"// before (config JSON for syntax.filemap)\n{\"\\.phpt$\": \"php\"}\n// after\n{\"/\\.phpt$/\": \"php\"}","handlingStrategy":"validation","validationCode":"// Validate every pattern key compiles under PCRE before saving config.\nforeach ($value as $pattern => $spec) {\n  if (@preg_match($pattern, '') === false) {\n    throw new Exception('Pattern will be rejected: '.$pattern);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["config","regex","phabricator","php","validation"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}