{"record":{"id":"261b1ea72ae4b431","repo":"phacility/phabricator","slug":"the-first-regexp-in-the-regexp-pair-s-is-not","errorCode":null,"errorMessage":"The first regexp in the regexp pair, \"%s\", is not a valid regexp.","messagePattern":"The first regexp in the regexp pair, \"(.+?)\", is not a valid regexp\\.","errorType":"validation","errorClass":"HeraldInvalidConditionException","httpStatus":null,"severity":"error","filePath":"src/applications/herald/adapter/HeraldAdapter.php","lineNumber":655,"sourceCode":"              'The regular expression pair \"%s\" is not valid JSON. Enter a '.\n              'valid JSON array with two elements.',\n              $condition_value));\n        }\n\n        if (count($json) != 2) {\n          throw new HeraldInvalidConditionException(\n            pht(\n              'The regular expression pair \"%s\" must have exactly two '.\n              'elements.',\n              $condition_value));\n        }\n\n        $key_regexp = array_shift($json);\n        $val_regexp = array_shift($json);\n\n        $key_ok = @preg_match($key_regexp, '');\n        if ($key_ok === false) {\n          throw new HeraldInvalidConditionException(\n            pht(\n              'The first regexp in the regexp pair, \"%s\", is not a valid '.\n              'regexp.',\n              $key_regexp));\n        }\n\n        $val_ok = @preg_match($val_regexp, '');\n        if ($val_ok === false) {\n          throw new HeraldInvalidConditionException(\n            pht(\n              'The second regexp in the regexp pair, \"%s\", is not a valid '.\n              'regexp.',\n              $val_regexp));\n        }\n        break;\n      case self::CONDITION_CONTAINS:\n      case self::CONDITION_NOT_CONTAINS:\n      case self::CONDITION_IS:","sourceCodeStart":637,"sourceCodeEnd":673,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/herald/adapter/HeraldAdapter.php#L637-L673","documentation":"Thrown by HeraldAdapter::willSaveCondition() for CONDITION_REGEXP_PAIR after the JSON array was decoded and had exactly two elements. The first element is shifted off as the key regexp and smoke-tested with @preg_match($key_regexp, ''); a boolean false return (invalid PCRE pattern) raises this error, naming the first (key) regexp specifically.","triggerScenarios":"Saving a regexp pair like [\"title.*\", \"@value@\"] — the first element lacks delimiters, has an unbalanced delimiter, an invalid modifier, or a PCRE syntax error. The second element is validated separately, so this error points only at element zero.","commonSituations":"Users add delimiters to one element of the pair but not the other, or paste a bare grep-style pattern as the key matcher while correctly formatting the value matcher.","solutions":["Fix the FIRST element of the JSON array so it is a valid PCRE pattern with delimiters, e.g. \"@^title$@\".","Escape or change the delimiter if the pattern itself contains it.","Test the key pattern standalone: php -r 'var_dump(@preg_match(\"@^title$@\", \"\"));' — it must not print bool(false)."],"exampleFix":"// before\n[\"^title$\", \"@urgent@\"]\n\n// after\n[\"@^title$@\", \"@urgent@\"]","handlingStrategy":"validation","validationCode":"list($key_re, $val_re) = phutil_json_decode($value);\nif (@preg_match($key_re, '') === false) {\n  return pht('First regexp of the pair is invalid; add delimiters.');\n}","typeGuard":"function isValidRegexpPairKey($pair_json) {\n  $json = phutil_json_decode($pair_json);\n  return @preg_match($json[0], '') !== false;\n}","tryCatchPattern":"try {\n  $editor->save();\n} catch (HeraldInvalidConditionException $ex) {\n  // 'first regexp ... is not valid' -> fix element 0 only, then resubmit\n}","preventionTips":["Validate BOTH pair elements with @preg_match($re, '') in one pre-save pass; errors 823 and 824 surface one at a time.","Use a shared regexp sanitizer so key and value patterns are formatted identically."],"tags":["herald","phabricator","php","regex","pcre","validation","rule-engine"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}