{"record":{"id":"c2cefcaab09ff7ce","repo":"symfony/http-kernel","slug":"invalid-regular-expression-in-the-s-argument-of-s-s","errorCode":null,"errorMessage":"Invalid regular expression in the \"$%s\" argument of \"%s\": \"%s\".","messagePattern":"Invalid regular expression in the \"\\$(.+?)\" argument of \"(.+?)\": \"(.+?)\"\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"EventListener/ProfilerListener.php","lineNumber":202,"sourceCode":"\n        if (!\\array_key_exists($code = $response->getStatusCode(), $this->excludedHttpCodePatterns)) {\n            return false;\n        }\n\n        $pattern = $this->excludedHttpCodePatterns[$code];\n\n        return null === $pattern || preg_match($pattern, $pathInfo);\n    }\n\n    /**\n     * @param list<string> $regexps\n     */\n    private static function compilePattern(array $regexps, string $argument): string\n    {\n        $pattern = '{('.implode('|', $regexps).')}';\n\n        if (false === @preg_match($pattern, '')) {\n            throw new \\LogicException(\\sprintf('Invalid regular expression in the \"$%s\" argument of \"%s\": \"%s\".', $argument, self::class, implode('\", \"', $regexps)));\n        }\n\n        return $pattern;\n    }\n}\n","sourceCodeStart":184,"sourceCodeEnd":208,"githubUrl":"https://github.com/symfony/http-kernel/blob/aa3a39d7286a62cdfea98f0e69c651a3da6e36cf/EventListener/ProfilerListener.php#L184-L208","documentation":"ProfilerListener builds a combined regex from configured path/exception exclusion patterns and validates it with preg_match at construction. If the assembled pattern is not a valid PCRE, a LogicException is thrown listing the offending patterns.","triggerScenarios":"Constructing ProfilerListener with invalid regexes in the 'path_only'/'excluded-urls' style option arrays, e.g. an unbalanced delimiter or invalid modifier in a framework.profiler setting or manual new ProfilerListener(...) call.","commonSituations":"Typo in symfony/profiler excluded_urls config (missing delimiters like '#' or '/'); copying a pattern from another tool with unsupported syntax; concatenating user config into regexes.","solutions":["Fix the configured pattern so it is a valid delimited PCRE, e.g. '^/api/' instead of '/api/'.","Validate each regex with @preg_match() in a config test or lint before deployment.","Use plain prefixes or a dedicated matcher option if regex escaping is error-prone."],"exampleFix":"// before (config)\nprofiler: { excluded_urls: '^/health$' }\n// after\nprofiler: { excluded_urls: '#^/health$#' }","handlingStrategy":"validation","validationCode":"foreach ($patterns as $p) { if (@preg_match('#^'.str_replace('#','\\#',$p).'#', '') === false) { throw new \\InvalidArgumentException(\"Invalid regex: $p\"); } }","typeGuard":null,"tryCatchPattern":"try { $listener = new ProfilerListener(...); } catch (\\LogicException $e) { /* log and surface the bad config key to the user */ throw new \\RuntimeException($e->getMessage(), 0, $e); }","preventionTips":["Always include PCRE delimiters in configured patterns","Lint regex config in CI with preg_match before deploy","Escape user-supplied input with preg_quote before embedding in patterns"],"tags":["regex","profiler","configuration","symfony"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"aa3a39d7286a62cdfea98f0e69c651a3da6e36cf","analyzedAt":"2026-09-13T18:03:36.509Z","contentChangedAt":"2026-09-13T18:03:36.509Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}