Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
ECMAScript (JavaScript)

/
^((?!^\/api\/auth\/|\/(favicon|icon|apple-icon)\.(ico|jpg|jpeg|png|svg)$|^\/(assets|public)\/).)*$
/
gm

Description

Next.js middleware config matcher regex

~ https://nextjs.org/docs/app/building-your-application/routing/middleware#matcher

~ https://nextjs.org/docs/app/api-reference/file-conventions/middleware#config-object-optional

Public - skip middleware

/api/auth/* /favicon.ico /assets/* /public/*

Private - use middleware

/* /api/*

Submitted by iki - 4 months ago