{"record":{"id":"193b495d8672413f","repo":"phacility/phabricator","slug":"the-second-regexp-in-the-regexp-pair-s-is-not","errorCode":null,"errorMessage":"The second regexp in the regexp pair, \"%s\", is not a valid regexp.","messagePattern":"The second 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":664,"sourceCode":"              '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:\n      case self::CONDITION_IS_NOT:\n      case self::CONDITION_IS_ANY:\n      case self::CONDITION_IS_NOT_ANY:\n      case self::CONDITION_INCLUDE_ALL:\n      case self::CONDITION_INCLUDE_ANY:\n      case self::CONDITION_INCLUDE_NONE:\n      case self::CONDITION_IS_ME:\n      case self::CONDITION_IS_NOT_ME:\n      case self::CONDITION_RULE:","sourceCodeStart":646,"sourceCodeEnd":682,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/herald/adapter/HeraldAdapter.php#L646-L682","documentation":"Thrown by HeraldAdapter::willSaveCondition() for CONDITION_REGEXP_PAIR after the JSON array decoded correctly, had exactly two elements, and the first (key) regexp passed validation. The second element is shifted off as the value regexp and smoke-tested with @preg_match($val_regexp, ''); a boolean false return raises this error, naming the second (value) regexp specifically.","triggerScenarios":"Saving a regexp pair like [\"@^title$@\", \"urgent.*\"] where only the SECOND element is a broken PCRE pattern (no delimiters, unbalanced delimiter, invalid modifier, syntax error). If you get this after error 823, you already fixed the key and now only the value pattern is still wrong.","commonSituations":"Fixing the first regexp after a pair-validation failure but leaving the second one unedited; or building pairs programmatically where only the value slot receives unformatted user input.","solutions":["Fix the SECOND element of the JSON array to be a valid delimited PCRE pattern, e.g. \"@urgent@\".","Re-test the whole pair rather than one element, since both are validated independently.","Escape delimiter characters inside the pattern or choose a different delimiter."],"exampleFix":"// before\n[\"@^title$@\", \"urgent|asap\"]\n\n// after\n[\"@^title$@\", \"@(urgent|asap)@\"]","handlingStrategy":"validation","validationCode":"list($key_re, $val_re) = phutil_json_decode($value);\nif (@preg_match($val_re, '') === false) {\n  return pht('Second regexp of the pair is invalid; add delimiters.');\n}","typeGuard":"function isValidRegexpPairValue($pair_json) {\n  $json = phutil_json_decode($pair_json);\n  return @preg_match($json[1], '') !== false;\n}","tryCatchPattern":"try {\n  $editor->save();\n} catch (HeraldInvalidConditionException $ex) {\n  // 'second regexp ... is not valid' -> only element 1 needs fixing\n}","preventionTips":["After fixing the first element of a pair, immediately re-test the second — the two checks run sequentially.","Write pairs in a builder that formats both regexes through the same delimiter-adding helper."],"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"}