# Next.js: Error: Invalid middleware found. Capturing groups are not allowed in matcher / `matcher` values must start with `/`

**Code:** `Middleware matcher: Capturing groups are not allowed` · **Category:** Next.js · **Seen on:** Next.js

The `config.matcher` regex in middleware contains an unsupported pattern (capturing group) or invalid syntax.

## Meaning

Use non-capturing groups `(?:...)` and negative lookaheads: `/((?!api|_next/static|_next/image|favicon.ico).*)`. Each matcher string must start with `/` and be a valid path-to-regexp pattern. Check for stray parentheses and unsupported flags.

## Common causes

- Capturing group `(foo|bar)` in matcher
- Matcher string not starting with `/`
- Invalid regex syntax
- Using full regex literal instead of string
- Copy from old Next.js version

## Quick fix

1. Use `"/((?!api|_next/static|_next/image|favicon.ico).*)"`
2. Ensure strings start with `/`
3. Test patterns in the Next.js matcher docs

## Detailed fix by platform

### Next.js

1. `export const config = { matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"] };`

## How to diagnose

1. **Pattern** — Capturing groups?
2. **Prefix** — Starts with /?
3. **Syntax** — Valid?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/nextjs/matcher-capturing-groups-not-allowed)
