{"record":{"id":"06c3d494426e6a52","repo":"phacility/phabricator","slug":"first-regular-expression-is-invalid","errorCode":null,"errorMessage":"First regular expression is invalid!","messagePattern":"First regular expression is invalid!","errorType":"validation","errorClass":"HeraldInvalidConditionException","httpStatus":null,"severity":"error","filePath":"src/applications/herald/adapter/HeraldAdapter.php","lineNumber":574,"sourceCode":"        $regexp_pair = null;\n        try {\n          $regexp_pair = phutil_json_decode($condition_value);\n        } catch (PhutilJSONParserException $ex) {\n          throw new HeraldInvalidConditionException(\n            pht('Regular expression pair is not valid JSON!'));\n        }\n        if (count($regexp_pair) != 2) {\n          throw new HeraldInvalidConditionException(\n            pht('Regular expression pair is not a pair!'));\n        }\n\n        $key_regexp   = array_shift($regexp_pair);\n        $value_regexp = array_shift($regexp_pair);\n\n        foreach ((array)$field_value as $key => $value) {\n          $key_matches = @preg_match($key_regexp, $key);\n          if ($key_matches === false) {\n            throw new HeraldInvalidConditionException(\n              pht('First regular expression is invalid!'));\n          }\n          if ($key_matches) {\n            $value_matches = @preg_match($value_regexp, $value);\n            if ($value_matches === false) {\n              throw new HeraldInvalidConditionException(\n                pht('Second regular expression is invalid!'));\n            }\n            if ($value_matches) {\n              return true;\n            }\n          }\n        }\n        return false;\n      case self::CONDITION_RULE:\n      case self::CONDITION_NOT_RULE:\n        $rule = $engine->getRule($condition_value);\n        if (!$rule) {","sourceCodeStart":556,"sourceCodeEnd":592,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/herald/adapter/HeraldAdapter.php#L556-L592","documentation":"In a regexp-pair condition, the adapter iterates the field's dictionary and runs @preg_match($key_regexp, $key). If preg_match returns false (invalid pattern — delimiter, syntax, or modifier errors), it throws HeraldInvalidConditionException('First regular expression is invalid!'). The failure is lazy: it only surfaces when rule evaluation actually reaches a key/value pair.","triggerScenarios":"The first (key) element of the JSON pair is not a valid PCRE pattern — e.g. 'foo' without delimiters, unbalanced delimiters, or an unknown modifier — and a rule evaluation matches the condition against a non-empty dictionary.","commonSituations":"Users enter bare patterns without /.../ delimiters in API-created conditions; escaping is lost one too many times through json_encode/manual editing; modifiers from other regex flavors (e.g. Python) are used.","solutions":["Wrap the key pattern in delimiters and verify it: php -r 'var_dump(@preg_match(\"/your-pattern/\", \"x\"));' must not return false.","Re-save the rule in the UI, testing the pattern in the condition editor.","Remove unsupported modifiers and use PCRE syntax."],"exampleFix":"// before (no delimiters on the key regexp)\n[\"^build-\", \"/nightly/\"]\n\n// after\n[\"/^build-/\", \"/nightly/\"]","handlingStrategy":"validation","validationCode":"// Validate the FIRST (key) regexp of the pair before saving:\ntry {\n  list($key_regexp, $value_regexp) = phutil_json_decode($value);\n} catch (PhutilJSONParserException $ex) {\n  // handle 814 first\n}\nif (@preg_match($key_regexp, '') === false) {\n  // key regexp is invalid - fix before saving the condition\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Wrap both patterns in delimiters (e.g. /build-.*/).","Validate both patterns with a bare @preg_match() before saving the rule."],"tags":["herald","regex","pcre","phabricator"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}