{
 "kind": "tool",
 "slug": "path-to-regexp",
 "path": "tools/path-to-regexp/",
 "name": "path-to-regexp",
 "maker": null,
 "density": "full",
 "crumbs": [
  [
   "Tools",
   "tools/"
  ],
  [
   "Utilities",
   "tools/utilities/"
  ]
 ],
 "lead": "Match web addresses like /users/:id.",
 "chips": [
  {
   "label": "Utilities",
   "path": "tools/utilities/"
  },
  {
   "label": "NPM"
  }
 ],
 "primary": {
  "label": "Copy install command",
  "copy": "npm install path-to-regexp"
 },
 "links": [
  {
   "label": "GitHub",
   "href": "https://github.com/pillarjs/path-to-regexp"
  },
  {
   "label": "Website",
   "href": "https://github.com/pillarjs/path-to-regexp#readme"
  }
 ],
 "track": "New versions, deprecation and license changes on your dashboard",
 "verdicts": [
  {
   "key": "license",
   "label": "License",
   "value": "MIT",
   "status": "yes",
   "sub": "Use it in paid apps",
   "quote": "The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.",
   "note": "Keep the MIT copyright and license notice with the package files you ship.",
   "src": "https://github.com/pillarjs/path-to-regexp/blob/master/LICENSE"
  },
  {
   "key": "maint",
   "label": "Maintained",
   "value": "Maintained",
   "status": "yes",
   "sub": "Last change Nov 21, 2026",
   "note": "Latest GitHub release Oct 22, 2026. ",
   "src": "https://github.com/pillarjs/path-to-regexp"
  },
  {
   "key": "pop",
   "label": "Used by agents' projects",
   "value": "9 projects",
   "status": "info",
   "sub": "#126 of 408 in its category",
   "note": "Dependency in 9 public GitHub projects set up for AI coding agents that we scanned (0.1%).",
   "src": null
  },
  {
   "key": "agent",
   "label": "Agent access",
   "value": "Install only",
   "status": "info",
   "sub": null,
   "note": "Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.",
   "src": null
  }
 ],
 "vfoot": "From the package registry and GitHub, checked daily; card checked Nov 11, 2026.",
 "blocks": [
  {
   "id": "overview",
   "nav": "Overview",
   "h2": "What path-to-regexp does",
   "parts": [
    {
     "t": "prose",
     "text": "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."
    },
    {
     "t": "h3",
     "text": "What people build with it"
    },
    {
     "t": "uses",
     "items": [
      {
       "title": "A small router without a framework",
       "text": "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.",
       "idea": false
      },
      {
       "title": "Build links from a route pattern",
       "text": "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.",
       "idea": false
      },
      {
       "title": "Pages with an optional part",
       "text": "One route answers both /image and /image.png, or both /users/delete and /users/7/delete.",
       "idea": false
      },
      {
       "title": "Lock whole sections behind a login",
       "text": "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.",
       "idea": true
      },
      {
       "title": "Move route paths to Express 5",
       "text": "When an older Express app moves to version 5, routes such as /* or /:ext? must be rewritten in the new pattern style.",
       "idea": false
      }
     ]
    }
   ]
  },
  {
   "id": "popularity",
   "nav": "Popularity",
   "h2": "path-to-regexp popularity",
   "parts": [
    {
     "t": "stats",
     "items": [
      {
       "n": "63",
       "of": "/ 100",
       "l": "Gid Score, #774 overall"
      },
      {
       "n": "336M",
       "l": "downloads a week, npm"
      },
      {
       "n": "8,620",
       "l": "GitHub stars"
      },
      {
       "n": "9",
       "l": "agent projects use it"
      }
     ]
    },
    {
     "t": "small",
     "text": "Gid Score measures public popularity and activity, not quality.",
     "link": "How the Gid Score is calculated",
     "path": "tools/top/"
    }
   ]
  },
  {
   "id": "usage",
   "nav": "How it is used",
   "h2": "How path-to-regexp is used",
   "parts": [
    {
     "t": "list",
     "items": [
      "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%)."
     ]
    },
    {
     "t": "h3",
     "text": "By coding agent"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "8 projects, 0.2%",
       "v": "Claude Code",
       "path": "agents/claude-code/"
      },
      {
       "l": "7 projects, 0.3%",
       "v": "Cursor",
       "path": "agents/cursor/"
      },
      {
       "l": "5 projects, 0.2%",
       "v": "GitHub Copilot",
       "path": "agents/github-copilot/"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Often used with"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "In 68.8% of its projects",
       "v": "Husky",
       "path": "tools/husky/"
      },
      {
       "l": "In 68.8% of its projects",
       "v": "lint-staged",
       "path": "tools/lint-staged/"
      },
      {
       "l": "In 62.5% of its projects",
       "v": "GraphQL.js",
       "path": "tools/graphql/"
      },
      {
       "l": "In 68.8% of its projects",
       "v": "Vite",
       "path": "tools/vite/"
      },
      {
       "l": "In 56.2% of its projects",
       "v": "Testing Library",
       "path": "tools/testing-library/"
      },
      {
       "l": "In 56.2% of its projects",
       "v": "Day.js",
       "path": "tools/dayjs/"
      },
      {
       "l": "In 56.2% of its projects",
       "v": "graphql-ws",
       "path": "tools/graphql-ws/"
      },
      {
       "l": "In 56.2% of its projects",
       "v": "ws",
       "path": "tools/ws/"
      }
     ]
    }
   ]
  },
  {
   "id": "more",
   "nav": null,
   "spy_as": "usage",
   "h2": "More about path-to-regexp",
   "parts": [
    {
     "t": "more",
     "items": [
      {
       "title": "Funding",
       "path": "tools/funding/",
       "items": [
        "Open Collective: https://opencollective.com/express"
       ]
      },
      {
       "title": "More in Utilities",
       "path": "tools/utilities/",
       "items": [
        {
         "text": "clsx",
         "path": "tools/clsx/"
        },
        {
         "text": "date-fns",
         "path": "tools/date-fns/"
        },
        {
         "text": "PyYAML",
         "path": "tools/pyyaml/"
        },
        {
         "text": "uuid",
         "path": "tools/uuid/"
        },
        {
         "text": "yaml",
         "path": "tools/yaml/"
        },
        {
         "text": "js-yaml",
         "path": "tools/js-yaml/"
        },
        {
         "text": "glob",
         "path": "tools/glob/"
        },
        {
         "text": "Lodash",
         "path": "tools/lodash/"
        }
       ]
      }
     ]
    }
   ]
  },
  {
   "id": "alternatives",
   "nav": "Alternatives",
   "h2": "Alternatives",
   "parts": [
    {
     "t": "alts",
     "items": [
      {
       "name": "path-to-regexp",
       "me": true,
       "facts": [
        "MIT",
        "Gid 63",
        "336M/wk"
       ]
      },
      {
       "name": "Express",
       "why": "Pick Express when you want a whole Node.js web server with routing built in rather than only the matching step.",
       "path": "tools/express/",
       "facts": []
      },
      {
       "name": "Hono",
       "why": "Pick Hono when you need a full router and request handling for edge or serverless platforms.",
       "path": "tools/hono/",
       "facts": []
      },
      {
       "name": "picomatch",
       "why": "Pick picomatch when you match file paths with glob patterns like src/**/*.js, not web addresses.",
       "path": "tools/picomatch/",
       "facts": []
      }
     ],
     "more": "Compare path-to-regexp with another tool",
     "more_path": "tools/compare/"
    }
   ]
  },
  {
   "id": "start",
   "nav": "Get started",
   "h2": "Get started",
   "parts": [
    {
     "t": "prompt",
     "text": "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."
    },
    {
     "t": "steps",
     "items": [
      {
       "text": "Add the package to your project.",
       "code": "npm install path-to-regexp --save",
       "src": "https://github.com/pillarjs/path-to-regexp/blob/master/Readme.md"
      },
      {
       "text": "Make a matcher from a pattern and call it with an address; you get the parts as params, or false.",
       "code": "import { match, pathToRegexp, compile, parse, stringify } from \"path-to-regexp\";\n\nconst fn = match(\"/:foo/:bar\");\n\nfn(\"/test/route\");\n//=> { path: '/test/route', params: { foo: 'test', bar: 'route' } }\n",
       "src": "https://github.com/pillarjs/path-to-regexp/blob/master/Readme.md"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Mistakes to avoid"
    },
    {
     "t": "mistakes",
     "items": [
      {
       "dont": "match('/users/:id?') or app.get('/*', ...) written in the Express 4 style",
       "fix": "Use braces for optional parts and name every wildcard, e.g. '/users{/:id}' and '/*splat' (or '/{*splat}' to include '/')",
       "why": "Since version 8 these characters are reserved; in our run 9.0.0 threw 'TypeError Unexpected ? at index 10' and 'Missing parameter name'."
      },
      {
       "dont": "const { match } = require('path-to-regexp') on version 9, or running it on Node.js 20",
       "fix": "Use import on Node.js 22+, or pin path-to-regexp@8.4.2 for a CommonJS project on older Node.js",
       "why": "Version 9.0.0 ships only an ES module build and requires Node.js 22 or newer."
      },
      {
       "dont": "match('/users/:id')(request.url) with the query string still attached",
       "fix": "Match only the pathname, e.g. new URL(request.url).pathname, and read the query with URLSearchParams",
       "why": "In our run '/users/42?tab=posts' gave id '42?tab=posts'; the README says query strings are not handled."
      },
      {
       "dont": "Listing '/users/:id' before '/users{/:id}/delete' and expecting /users/delete to reach the delete handler",
       "fix": "Put the more specific routes first, or check them in a fixed order you control",
       "why": "A parameter takes any text up to the next slash, so in our run /users/delete matched '/users/:id' with id 'delete'."
      },
      {
       "dont": "Staying on path-to-regexp 0.1.12 or 8.0–8.3, or building route patterns from user input",
       "fix": "Use 0.1.13 (Express 4) or 8.4.0+ / 9.x, and only use patterns written by you",
       "why": "Several advisories describe patterns that make the generated check very slow, a denial-of-service risk."
      }
     ]
    }
   ]
  },
  {
   "id": "faq",
   "nav": "Questions",
   "h2": "Questions",
   "parts": [
    {
     "t": "faq",
     "items": [
      {
       "q": "What is the difference between /users/:id and /docs/*path?",
       "a": ":id matches one part between slashes; *path matches one or more parts and gives them back as a list.",
       "evidence": {
        "url": "https://github.com/pillarjs/path-to-regexp/blob/master/Readme.md",
        "quote": "Wildcard parameters match one or more characters across multiple segments."
       }
      },
      {
       "q": "How do I make part of a route optional?",
       "a": "Wrap it in braces, for example /users{/:id}/delete or /:file{.:ext}. The old ? suffix is not supported.",
       "evidence": {
        "url": "https://github.com/pillarjs/path-to-regexp/blob/master/Readme.md",
        "quote": "For optional (?), use braces: /file{.:ext}."
       }
      },
      {
       "q": "Which version does Express use?",
       "a": "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.",
       "evidence": {
        "url": "https://github.com/pillarjs/path-to-regexp/blob/master/Readme.md",
        "quote": "Path-To-RegExp breaks compatibility with Express <= 4.x in the following ways:"
       }
      },
      {
       "q": "What does it do with two parts in one segment, like /:name.:ext?",
       "a": "Since version 9 the last part takes the extra text, so /foo.json.html gives name foo and ext json.html.",
       "evidence": {
        "url": "https://github.com/pillarjs/path-to-regexp/releases/tag/v9.0.0",
        "quote": "The primary incompatible API change is to switch ambiguous matches (2+ parameters in a segment) from the first being greedy to the last."
       }
      },
      {
       "q": "Does it decode characters like %C3%A9?",
       "a": "Yes. match() decodes parameters with decodeURIComponent and compile() encodes them, unless you turn that off.",
       "evidence": {
        "url": "https://github.com/pillarjs/path-to-regexp/blob/master/Readme.md",
        "quote": "decode Function for decoding strings to params, or false to disable all processing. (default: decodeURIComponent)"
       }
      }
     ]
    }
   ]
  }
 ],
 "glance": [
  [
   "Package",
   "npm path-to-regexp"
  ],
  [
   "Category",
   "Utilities"
  ],
  [
   "License",
   "MIT"
  ],
  [
   "Gid Score",
   "63.4"
  ],
  [
   "Rank in category",
   "#126 of 408"
  ],
  [
   "GitHub",
   "pillarjs/path-to-regexp"
  ],
  [
   "Last change",
   "Nov 21, 2026"
  ]
 ],
 "good": [
  "Version 9 runs only as an ES module and needs Node.js 22 or newer.",
  "It is for the path part of an address only. The part after a question mark, such as ?tab=posts, has to be read separately.",
  "The pattern style changed in version 8. Old patterns with ?, an unnamed * or brackets now stop with an error."
 ],
 "checked_line": "Read by AgentGid from 10 official pages, card checked Nov 11, 2026; numbers update daily.",
 "logo": "https://agentgid.com/media/avatars/pillarjs.png"
}