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/LICENSE3. Used by agents' projects
Dependency in 9 public GitHub projects set up for AI coding agents that we scanned (0.1%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
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
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
Often used with
More about path-to-regexp
Funding
- Open Collective: https://opencollective.com/express
Alternatives
path-to-regexp This page
Pick Express when you want a whole Node.js web server with routing built in rather than only the matching step.
Pick Hono when you need a full router and request handling for edge or serverless platforms.
Pick picomatch when you match file paths with glob patterns like src/**/*.js, not web addresses.
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.”
Add the package to your project.
npm install path-to-regexp --saveFrom github.com/pillarjs/path-to-regexp/blob/master/Readme.md
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
Since version 8 these characters are reserved; in our run 9.0.0 threw 'TypeError Unexpected ? at index 10' and 'Missing parameter name'.
Version 9.0.0 ships only an ES module build and requires Node.js 22 or newer.
In our run '/users/42?tab=posts' gave id '42?tab=posts'; the README says query strings are not handled.
A parameter takes any text up to the next slash, so in our run /users/delete matched '/users/:id' with id 'delete'.
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.