{"id":23053680,"url":"https://github.com/component/path-to-regexp","last_synced_at":"2026-03-15T22:47:19.758Z","repository":{"id":20188555,"uuid":"23459649","full_name":"component/path-to-regexp","owner":"component","description":"DEPRECATED use https://github.com/pillarjs/path-to-regexp","archived":false,"fork":false,"pushed_at":"2024-08-22T01:29:02.000Z","size":9,"stargazers_count":52,"open_issues_count":0,"forks_count":7,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-07-17T05:34:43.286Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/component.png","metadata":{"files":{"readme":"Readme.md","changelog":"History.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-29T09:41:23.000Z","updated_at":"2025-01-05T11:14:51.000Z","dependencies_parsed_at":"2022-08-02T10:37:08.786Z","dependency_job_id":null,"html_url":"https://github.com/component/path-to-regexp","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/component/path-to-regexp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/component%2Fpath-to-regexp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/component%2Fpath-to-regexp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/component%2Fpath-to-regexp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/component%2Fpath-to-regexp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/component","download_url":"https://codeload.github.com/component/path-to-regexp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/component%2Fpath-to-regexp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270523888,"owners_count":24600186,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-15T02:00:12.559Z","response_time":110,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-16T00:19:08.292Z","updated_at":"2026-03-15T22:47:14.737Z","avatar_url":"https://github.com/component.png","language":"JavaScript","readme":"# Path-to-RegExp\n\nTurn an Express-style path string such as `/user/:name` into a regular expression.\n\n[![NPM version][npm-image]][npm-url]\n[![Build status][travis-image]][travis-url]\n[![Test coverage][coveralls-image]][coveralls-url]\n\n## Installation\n\n```\nnpm install path-to-regexp --save\n```\n\n## Usage\n\n```javascript\nvar pathToRegexp = require('path-to-regexp');\n\n// pathToRegexp(path, keys, options);\n```\n\n- **path** A string in the express format, an array of strings, or a regular expression.\n- **keys** An array to be populated with the keys present in the url.\n- **options**\n  - **sensitive** When `true` the route will be case sensitive. (default: `false`)\n  - **strict** When `false` the trailing slash is optional. (default: `false`)\n  - **end** When `false` the path will match at the beginning. (default: `true`)\n\n```javascript\nvar keys = [];\nvar re = pathToRegexp('/foo/:bar', keys);\n// re = /^\\/foo\\/([^\\/]+?)\\/?$/i\n// keys = [{ name: 'bar', delimiter: '/', repeat: false, optional: false }]\n```\n\n### Parameters\n\nThe path has the ability to define parameters and automatically populate the keys array.\n\n#### Named Parameters\n\nNamed parameters are defined by prefixing a colon to the parameter name (`:foo`). By default, this parameter will match up to the next path segment.\n\n```js\nvar re = pathToRegexp('/:foo/:bar', keys);\n// keys = [{ name: 'foo', ... }, { name: 'bar', ... }]\n\nre.exec('/test/route');\n//=\u003e ['/test/route', 'test', 'route']\n```\n\n#### Suffixed Parameters\n\n##### Optional\n\nParameters can be suffixed with a question mark (`?`) to make the entire parameter optional. This will also make any prefixed path delimiter optional (`/` or `.`).\n\n```js\nvar re = pathToRegexp('/:foo/:bar?', keys);\n// keys = [{ name: 'foo', ... }, { name: 'bar', delimiter: '/', optional: true, repeat: false }]\n\nre.exec('/test');\n//=\u003e ['/test', 'test', undefined]\n\nre.exec('/test/route');\n//=\u003e ['/test', 'test', 'route']\n```\n\n##### Zero or more\n\nParameters can be suffixed with an asterisk (`*`) to denote a zero or more parameter match. The prefixed path delimiter is also taken into account for the match.\n\n```js\nvar re = pathToRegexp('/:foo*', keys);\n// keys = [{ name: 'foo', delimiter: '/', optional: true, repeat: true }]\n\nre.exec('/');\n//=\u003e ['/', undefined]\n\nre.exec('/bar/baz');\n//=\u003e ['/bar/baz', 'bar/baz']\n```\n\n##### One or more\n\nParameters can be suffixed with a plus sign (`+`) to denote a one or more parameters match. The prefixed path delimiter is included in the match.\n\n```js\nvar re = pathToRegexp('/:foo+', keys);\n// keys = [{ name: 'foo', delimiter: '/', optional: false, repeat: true }]\n\nre.exec('/');\n//=\u003e null\n\nre.exec('/bar/baz');\n//=\u003e ['/bar/baz', 'bar/baz']\n```\n\n#### Custom Match Parameters\n\nAll parameters can be provided a custom matching regexp and override the default. Please note: Backslashes need to be escaped in strings.\n\n```js\nvar re = pathToRegexp('/:foo(\\\\d+)', keys);\n// keys = [{ name: 'foo', ... }]\n\nre.exec('/123');\n//=\u003e ['/123', '123']\n\nre.exec('/abc');\n//=\u003e null\n```\n\n#### Unnamed Parameters\n\nIt is possible to write an unnamed parameter that is only a matching group. It works the same as a named parameter, except it will be numerically indexed.\n\n```js\nvar re = pathToRegexp('/:foo/(.*)', keys);\n// keys = [{ name: 'foo', ... }, { name: '0', ... }]\n\nre.exec('/test/route');\n//=\u003e ['/test/route', 'test', 'route']\n```\n\n## Compatibility with Express \u003c= 4.x\n\nPath-To-RegExp breaks compatibility with Express \u003c= 4.x in a few ways:\n\n* RegExp special characters can now be used in the regular path. E.g. `/user[(\\\\d+)]`\n* All RegExp special characters can now be used inside the custom match. E.g. `/:user(.*)`\n* No more support for asterisk matching - use an explicit parameter instead. E.g. `/(.*)`\n* Parameters can have suffixes that augment meaning - `*`, `+` and `?`. E.g. `/:user*`\n* Strings aren't interpreted as literal regexp strings - no more non-capturing groups, lookaheads, lookbehinds or nested matching groups (but you can still pass a regexp manually)\n\n## Live Demo\n\nYou can see a live demo of this library in use at [express-route-tester](http://forbeslindesay.github.com/express-route-tester/).\n\n## License\n\nMIT\n\n[npm-image]: https://img.shields.io/npm/v/path-to-regexp.svg?style=flat\n[npm-url]: https://npmjs.org/package/path-to-regexp\n[travis-image]: https://img.shields.io/travis/component/path-to-regexp.svg?style=flat\n[travis-url]: https://travis-ci.org/component/path-to-regexp\n[coveralls-image]: https://img.shields.io/coveralls/component/path-to-regexp.svg?style=flat\n[coveralls-url]: https://coveralls.io/r/component/path-to-regexp?branch=master\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcomponent%2Fpath-to-regexp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcomponent%2Fpath-to-regexp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcomponent%2Fpath-to-regexp/lists"}