Skip to content
Agents tracked: 506 Releases (7d): 634 Agent status: 3 with issuesSince last limit reset: Claude 15d · Codex 0d For AI agents: Markdown Updated Nov 26, 2026

path-to-regexp

Match web addresses like /users/:id.

UtilitiesNPM

GitHubWebsite

1. License

“The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.”

Keep the MIT copyright and license notice with the package files you ship.

github.com/pillarjs/path-to-regexp/blob/master/LICENSE

From the package registry and GitHub, checked daily; card checked Nov 11, 2026. Tap a verdict to see its source.How we checkedReport an error

What path-to-regexp does

path-to-regexp is a small free JavaScript library that checks a web address against route patterns such as /users/:id and reads out the parts, here id. It also works the other way and builds a correct address from those parts. Express uses this pattern style for its routes.

What people build with it

A small router without a framework

Your edge function or tiny server gets an address like /users/42 and needs to know which handler runs and which user was asked for.

Build links from a route pattern

Menus and emails link to /blog/2026/hello-world; you fill the pattern once instead of gluing strings by hand, and odd characters get encoded.

Pages with an optional part

One route answers both /image and /image.png, or both /users/delete and /users/7/delete.

Lock whole sections behind a login Idea

A check before every request decides if the address is under /admin or /account and sends visitors without a session to the sign-in page.

Move route paths to Express 5

When an older Express app moves to version 5, routes such as /* or /:ext? must be rewritten in the new pattern style.

path-to-regexp popularity

63 / 100
Gid Score, #774 overall
336M
downloads a week, npm
8,620
GitHub stars
9
agent projects use it
path-to-regexp: downloads per weeknpm, path-to-regexp 335,913,491
path-to-regexp: GitHub starspillarjs/path-to-regexp 8,620

Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated

How path-to-regexp is used

  • path-to-regexp joined the catalog on its public numbers (335,913,491 downloads a week on npm and 8,620 GitHub stars), not on our project count: it is a dependency in 16 public GitHub projects of our scan, 9 of them set up for AI coding agents.
  • Projects that use it most often also use Husky (68.8%), lint-staged (68.8%), GraphQL.js (62.5%).

By coding agent

8 projects, 0.2%
7 projects, 0.3%
5 projects, 0.2%

Often used with

In 68.8% of its projects
In 68.8% of its projects
In 62.5% of its projects
In 68.8% of its projects
In 56.2% of its projects
In 56.2% of its projects
In 56.2% of its projects
In 56.2% of its projects

More about path-to-regexp

Funding
  • Open Collective: https://opencollective.com/express

See all

More in Utilities

Alternatives

path-to-regexp This page

MITGid 63336M/wk

Express

Pick Express when you want a whole Node.js web server with routing built in rather than only the matching step.

Hono

Pick Hono when you need a full router and request handling for edge or serverless platforms.

picomatch

Pick picomatch when you match file paths with glob patterns like src/**/*.js, not web addresses.

Compare path-to-regexp with another tool

Get started

Tell your AI assistant

“Use the npm package path-to-regexp (pin path-to-regexp@9.0.0, ES modules, Node.js 22+) to match request paths against route patterns like /users/:id with match(), and build links with compile(); use braces for optional parts and named wildcards like /*path.”

  1. Add the package to your project.

    npm install path-to-regexp --save

    From github.com/pillarjs/path-to-regexp/blob/master/Readme.md

  2. Make a matcher from a pattern and call it with an address; you get the parts as params, or false.

    import { match, pathToRegexp, compile, parse, stringify } from "path-to-regexp";
    
    const fn = match("/:foo/:bar");
    
    fn("/test/route");
    //=> { path: '/test/route', params: { foo: 'test', bar: 'route' } }
    

    From github.com/pillarjs/path-to-regexp/blob/master/Readme.md

Mistakes to avoid

match('/users/:id?') or app.get('/*', ...) written in the Express 4 style
Use braces for optional parts and name every wildcard, e.g. '/users{/:id}' and '/*splat' (or '/{*splat}' to include '/')

Since version 8 these characters are reserved; in our run 9.0.0 threw 'TypeError Unexpected ? at index 10' and 'Missing parameter name'.

const { match } = require('path-to-regexp') on version 9, or running it on Node.js 20
Use import on Node.js 22+, or pin path-to-regexp@8.4.2 for a CommonJS project on older Node.js

Version 9.0.0 ships only an ES module build and requires Node.js 22 or newer.

match('/users/:id')(request.url) with the query string still attached
Match only the pathname, e.g. new URL(request.url).pathname, and read the query with URLSearchParams

In our run '/users/42?tab=posts' gave id '42?tab=posts'; the README says query strings are not handled.

Listing '/users/:id' before '/users{/:id}/delete' and expecting /users/delete to reach the delete handler
Put the more specific routes first, or check them in a fixed order you control

A parameter takes any text up to the next slash, so in our run /users/delete matched '/users/:id' with id 'delete'.

Staying on path-to-regexp 0.1.12 or 8.0–8.3, or building route patterns from user input
Use 0.1.13 (Express 4) or 8.4.0+ / 9.x, and only use patterns written by you

Several advisories describe patterns that make the generated check very slow, a denial-of-service risk.

Questions

What is the difference between /users/:id and /docs/*path?

:id matches one part between slashes; *path matches one or more parts and gives them back as a list.

How do I make part of a route optional?

Wrap it in braces, for example /users{/:id}/delete or /:file{.:ext}. The old ? suffix is not supported.

Which version does Express use?

Express 5 moved to the new pattern style; Express 4 stays on the old 0.1 line, which got its latest fix in 0.1.13.

What does it do with two parts in one segment, like /:name.:ext?

Since version 9 the last part takes the extra text, so /foo.json.html gives name foo and ext json.html.

Does it decode characters like %C3%A9?

Yes. match() decodes parameters with decodeURIComponent and compile() encodes them, unless you turn that off.