symfony/http-kernel · error · LogicException
Invalid regular expression in the "$
Error message
Invalid regular expression in the "$%s" argument of "%s": "%s".
What it means
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.
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.
Example fix
// before (config)
profiler: { excluded_urls: '^/health$' }
// after
profiler: { excluded_urls: '#^/health$#' } Defensive patterns
Strategy: validation
Validate before calling
foreach ($patterns as $p) { if (@preg_match('#^'.str_replace('#','\#',$p).'#', '') === false) { throw new \InvalidArgumentException("Invalid regex: $p"); } } Try / catch
try { $listener = new ProfilerListener(...); } catch (\LogicException $e) { /* log and surface the bad config key to the user */ throw new \RuntimeException($e->getMessage(), 0, $e); } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Unable to create the storage directory
- Rate limiter " " does not exist. Did you forget to…
- The " " renderer does not exist.
- You must use a URI when using the ESI rendering strategy or…
- Please check your configuration. You are trying to use…
AI-assisted analysis of symfony/http-kernel@aa3a39d728 (2026-09-13).
Data as JSON: /api/errors/c2cefcaab09ff7ce.
Report an issue: GitHub.
Appendix: source
Thrown at EventListener/ProfilerListener.php:202
if (!\array_key_exists($code = $response->getStatusCode(), $this->excludedHttpCodePatterns)) {
return false;
}
$pattern = $this->excludedHttpCodePatterns[$code];
return null === $pattern || preg_match($pattern, $pathInfo);
}
/**
* @param list<string> $regexps
*/
private static function compilePattern(array $regexps, string $argument): string
{
$pattern = '{('.implode('|', $regexps).')}';
if (false === @preg_match($pattern, '')) {
throw new \LogicException(\sprintf('Invalid regular expression in the "$%s" argument of "%s": "%s".', $argument, self::class, implode('", "', $regexps)));
}
return $pattern;
}
}
View on GitHub (pinned to aa3a39d728)