#2352·Ocelot

Matching routes using upstream headers triggers an odd `Regex` exception in dynamic routing mode

Author: xiexihuiCreated Jan 12, 2026Updated Sep 29, 2026
LabelsbugacceptedRoutingcriticalAutumn'26Dynamic Routing

sec-ch-ua "Microsoft Edge";v="143", "Chromium";v="143", "Not A(Brand";v="24"

fail: Ocelot.Errors.Middleware.ExceptionHandlerMiddleware[0]
      RequestId: 0HNIHMRHATJS9:00000003, PreviousRequestId: -
      RegexParseException caught in global error handler!
      DONE reporting of a total 0 inner exceptions for request 0HNIHMRHATJS9:00000003 of the original RegexParseException below ->
      System.Text.RegularExpressions.RegexParseException: Invalid pattern '^(?i)"Microsoft Edge";v="143", "Chromium";v="143", "Not A(Brand";v="24"$' at offset 72. Not enough )'s.
         at System.Text.RegularExpressions.RegexParser.ScanRegex()
         at System.Text.RegularExpressions.RegexParser.Parse(String pattern, RegexOptions options, CultureInfo culture)
         at System.Text.RegularExpressions.Regex..ctor(String pattern, RegexOptions options, TimeSpan matchTimeout, CultureInfo culture)
         at System.Text.RegularExpressions.Regex..ctor(String pattern, RegexOptions options, TimeSpan matchTimeout)
         at Ocelot.Infrastructure.RegexGlobal.New(String pattern, RegexOptions options)
         at Ocelot.Values.UpstreamHeaderTemplate..ctor(String template, String originalValue)
         at Ocelot.Configuration.Creator.UpstreamHeaderTemplatePatternCreator.Create(IDictionary`2 upstreamHeaderTemplates, Boolean routeIsCaseSensitive)
         at Ocelot.DownstreamRouteFinder.Finder.DiscoveryDownstreamRouteFinder.Get(String upstreamUrlPath, String upstreamQueryString, String upstreamHttpMethod, IInternalConfiguration configuration, String upstreamHost, IDictionary`2 upstreamHeaders)
         at Ocelot.DownstreamRouteFinder.Middleware.DownstreamRouteFinderMiddleware.Invoke(HttpContext httpContext)
         at Ocelot.Responder.Middleware.ResponderMiddleware.Invoke(HttpContext context)
         at Ocelot.Errors.Middleware.ExceptionHandlerMiddleware.Invoke(HttpContext context)