{"id":39836875,"url":"https://github.com/soongo/path-to-regexp","last_synced_at":"2026-01-18T13:22:46.215Z","repository":{"id":57506226,"uuid":"216476468","full_name":"soongo/path-to-regexp","owner":"soongo","description":"Turn a path string such as `/user/:name` into a regular expression","archived":false,"fork":false,"pushed_at":"2022-03-08T09:42:21.000Z","size":152,"stargazers_count":19,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-15T00:50:53.634Z","etag":null,"topics":["path","path-to-regexp","regexp","regular-expression","router","soon","soongo"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"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/soongo.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2019-10-21T04:18:50.000Z","updated_at":"2025-01-09T18:05:44.000Z","dependencies_parsed_at":"2022-08-29T20:00:48.057Z","dependency_job_id":null,"html_url":"https://github.com/soongo/path-to-regexp","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/soongo/path-to-regexp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soongo%2Fpath-to-regexp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soongo%2Fpath-to-regexp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soongo%2Fpath-to-regexp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soongo%2Fpath-to-regexp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/soongo","download_url":"https://codeload.github.com/soongo/path-to-regexp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soongo%2Fpath-to-regexp/sbom","scorecard":{"id":838232,"data":{"date":"2025-08-11","repo":{"name":"github.com/soongo/path-to-regexp","commit":"7705adbef633284f873e372073ba5edc0eb856f2"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.5,"checks":[{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-23T19:45:22.574Z","repository_id":57506226,"created_at":"2025-08-23T19:45:22.574Z","updated_at":"2025-08-23T19:45:22.574Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28536751,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T13:04:05.990Z","status":"ssl_error","status_checked_at":"2026-01-18T13:01:44.092Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["path","path-to-regexp","regexp","regular-expression","router","soon","soongo"],"created_at":"2026-01-18T13:22:46.147Z","updated_at":"2026-01-18T13:22:46.201Z","avatar_url":"https://github.com/soongo.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Path-to-RegExp\n\n[![Build Status](https://travis-ci.org/soongo/path-to-regexp.svg)](https://travis-ci.org/soongo/path-to-regexp)\n[![codecov](https://codecov.io/gh/soongo/path-to-regexp/branch/master/graph/badge.svg)](https://codecov.io/gh/soongo/path-to-regexp)\n[![Go Report Card](https://goreportcard.com/badge/github.com/soongo/path-to-regexp)](https://goreportcard.com/report/github.com/soongo/path-to-regexp)\n[![GoDoc](https://godoc.org/github.com/soongo/path-to-regexp?status.svg)](https://godoc.org/github.com/soongo/path-to-regexp)\n[![License](https://img.shields.io/badge/MIT-green.svg)](https://opensource.org/licenses/MIT)\n\n\u003e Turn a path string such as `/user/:name` into a regular expression.\n\nThanks to [path-to-regexp](https://github.com/pillarjs/path-to-regexp) which is the original version written in javascript.\n\n## Installation\n\nTo install `Path-to-RegExp` package, you need to install Go and set your Go workspace first.\n\nThe first need [Go](https://golang.org/) installed (**version 1.11+ is required**), then you can use the below Go command to install `Path-to-RegExp`.\n\n```sh\n$ go get -u github.com/soongo/path-to-regexp\n```\n\n#### Warning\n\n\u003e*Version 3.2.0, 4.0.0, 4.0.5, 5.0.0 have been removed, please use corresponding version 1.3.2, 1.4.0, 1.4.5, 1.5.0.*\n\n\n## Usage\n\n```go\nimport pathToRegexp \"github.com/soongo/path-to-regexp\"\n\n// pathToRegexp.PathToRegexp(path, tokens, options) // tokens and options can be nil\n// pathToRegexp.Parse(path, options) // options can be nil\n// pathToRegexp.Compile(path, options) // options can be nil\n// pathToRegexp.MustCompile(path, options) // like Compile but panics if the error is non-nil\n// pathToRegexp.Match(path, options) // options can be nil\n// pathToRegexp.MustMatch(path, options) // like Match but panics if the error is non-nil\n// pathToRegexp.Must(regexp, err) // wraps a call to a function returning (*regexp2.Regexp, error) and panics if the error is non-nil\n// pathToRegexp.EncodeURI(str) // encodes characters in URI except `;/?:@\u0026=+$,#`, like javascript's encodeURI\n// pathToRegexp.EncodeURIComponent(str) // encodes characters in URI, like javascript's encodeURIComponent\n```\n\n- **path** A string, array or slice of strings, or a regular expression with type *github.com/dlclark/regexp2.Regexp.\n- **tokens** An array to populate with tokens found in the path.\n  - token\n    - **Name** The name of the token (`string` for named or `number` for index)\n    - **Prefix** The prefix string for the segment (e.g. `\"/\"`)\n    - **Suffix** The suffix string for the segment (e.g. `\"\"`)\n    - **Pattern** The RegExp used to match this token (`string`)\n    - **Modifier** The modifier character used for the segment (e.g. `?`)\n- **options**\n  - **Sensitive** When `true` the regexp will be case sensitive. (default: `false`)\n  - **Strict** When `true` the regexp won't allow an optional trailing delimiter to match. (default: `false`)\n  - **End** When `true` the regexp will match to the end of the string. (default: `true`)\n  - **Start** When `true` the regexp will match from the beginning of the string. (default: `true`)\n  - **Validate** When `false` the function can produce an invalid (unmatched) path. (default: `true`)\n  - **Delimiter** The default delimiter for segments, e.g. `[^/#?]` for `:named` patterns. (default: `'/#?'`)\n  - **EndsWith** Optional character, or list of characters, to treat as \"end\" characters.\n  - **Prefixes** List of characters to automatically consider prefixes when parsing. (default: `./`)\n  - **Encode** How to encode uri. (default: `func (uri string, token interface{}) string { return uri }`)\n  - **Decode** How to decode uri. (default: `func (uri string, token interface{}) (string, error) { return uri }`)\n\n```go\nvar tokens []pathToRegexp.Token\nregexp := pathToRegexp.Must(pathToRegexp.PathToRegexp(\"/foo/:bar\", \u0026tokens, nil))\n// regexp: ^\\/foo(?:\\/([^\\/]+?))[\\/]?(?=$)\n// tokens: [{Name:\"bar\", Prefix:\"/\", Suffix:\"\", Pattern:\"[^\\\\/]+?\", Modifier:\"\"}]\n```\n\n**Please note:** The `Regexp` returned by `path-to-regexp` is intended for ordered data (e.g. pathnames, hostnames). It can not handle arbitrarily ordered data (e.g. query strings, URL fragments, JSON, etc). When using paths that contain query strings, you need to escape the question mark (`?`) to ensure it does not flag the parameter as [optional](#optional).\n\n### Parameters\n\nThe path argument is used to define parameters and populate tokens.\n\n#### Named Parameters\n\nNamed parameters are defined by prefixing a colon to the parameter name (`:foo`).\n\n```go\nvar tokens []pathToRegexp.Token\nregexp := pathToRegexp.Must(pathToRegexp.PathToRegexp(\"/:foo/:bar\", \u0026tokens, nil))\n// tokens: [\n//   {Name:\"foo\", Prefix:\"/\", Suffix:\"\", Pattern:\"[^\\\\/]+?\", Modifier:\"\"},\n//   {Name:\"bar\", Prefix:\"/\", Suffix:\"\", Pattern:\"[^\\\\/]+?\", Modifier:\"\"}\n// ]\n\nmatch, _ := regexp.FindStringMatch(\"/test/route\")\nfor _, g := range match.Groups() {\n    fmt.Printf(\"%q \", g.String())\n}\nfmt.Printf(\"%d %q\\n\", match.Index, match)\n//=\u003e \"/test/route\" \"test\" \"route\" 0 \"/test/route\"\n```\n\n**Please note:** Parameter names must use \"word characters\" (`[A-Za-z0-9_]`).\n\n##### Custom Matching Parameters\n\nParameters can have a custom regexp, which overrides the default match (`[^/]+`). For example, you can match digits or names in a path:\n\n```go\nvar tokens []pathToRegexp.Token\nregexpNumbers := pathToRegexp.Must(pathToRegexp.PathToRegexp(\"/icon-:foo(\\\\d+).png\", \u0026tokens, nil))\n// tokens: [{Name:\"foo\", Prefix:\"\", Suffix:\"\", Pattern:\"\\\\d+\", Modifier:\"\"}]\n\nmatch, _ := regexpNumbers.FindStringMatch(\"/icon-123.png\")\nfor _, g := range match.Groups() {\n    fmt.Printf(\"%q \", g.String())\n}\n//=\u003e \"/icon-123.png\" \"123\"\n\nmatch, _ := regexpNumbers.FindStringMatch(\"/icon-abc.png\")\nfmt.Println(match)\n//=\u003e \u003cnil\u003e\n\ntokens = make([]pathToRegexp.Token, 0)\nregexpWord := pathToRegexp.Must(pathToRegexp.PathToRegexp(\"/(user|u)\", \u0026tokens, nil))\n// tokens: [{Name:0, Prefix:\"/\", Suffix:\"\", Pattern:\"user|u\", Modifier:\"\"}]\n\nmatch, _ = regexpWord.FindStringMatch(\"/u\")\nfor _, g := range match.Groups() {\n    fmt.Printf(\"%q \", g.String())\n}\n//=\u003e \"/u\" \"u\"\n\nmatch, _ = regexpWord.FindStringMatch(\"users\")\nfmt.Println(match)\n//=\u003e \u003cnil\u003e\n```\n\n**Tip:** Backslashes need to be escaped with another backslash in JavaScript strings.\n\n##### Custom Prefix and Suffix\n\nParameters can be wrapped in `{}` to create custom prefixes or suffixes for your segment:\n\n```go\nregexp := pathToRegexp.Must(pathToRegexp.PathToRegexp(\"/:attr1?{-:attr2}?{-:attr3}?\", nil, nil))\n\nmatch, _ := regexp.FindStringMatch(\"/test\")\nfor _, g := range match.Groups() {\n    fmt.Printf(\"%q \", g.String())\n}\n//=\u003e \"/test\" \"test\" \"\" \"\"\n\nmatch, _ = regexp.FindStringMatch(\"/test-test\")\nfor _, g := range match.Groups() {\n    fmt.Printf(\"%q \", g.String())\n}\n//=\u003e \"/test-test\" \"test\" \"test\" \"\"\n```\n\n#### Unnamed Parameters\n\nIt is possible to write an unnamed parameter that only consists of a regexp. It works the same the named parameter, except it will be numerically indexed:\n\n```go\nvar tokens []pathToRegexp.Token\nregexp := pathToRegexp.Must(pathToRegexp.PathToRegexp(\"/:foo/(.*)\", \u0026tokens, nil))\n// tokens: [\n//   {Name:\"foo\", Prefix:\"/\", Suffix:\"\", Pattern:\"[^\\\\/]+?\", Modifier:\"\"}\n//   {Name:0, Prefix:\"/\", Suffix:\"\", Pattern:\".*\", Modifier:\"\"}\n// ]\n\nmatch, _ := regexp.FindStringMatch(\"/test/route\")\nfor _, g := range match.Groups() {\n    fmt.Printf(\"%q \", g.String())\n}\nfmt.Printf(\"%d %q\\n\", match.Index, match)\n//=\u003e \"/test/route\" \"test\" \"route\" 0 \"/test/route\"\n```\n\n#### Modifiers\n\nModifiers must be placed after the parameter (e.g. `/:foo?`, `/(test)?`, `/:foo(test)?`, or `{-:foo(test)}?`).\n\n##### Optional\n\nParameters can be suffixed with a question mark (`?`) to make the parameter optional.\n\n```go\nregexp := pathToRegexp.Must(pathToRegexp.PathToRegexp(\"/:foo/:bar?\", nil, nil))\n// tokens: [\n//   {Name:\"foo\", Prefix:\"/\", Suffix:\"\", Pattern:\"[^\\\\/]+?\", Modifier:\"\"}\n//   {Name:\"bar\", Prefix:\"/\", Suffix:\"\", Pattern:\"[^\\\\/]+?\", Modifier:\"?\"}\n// ]\n\nmatch, _ := regexp.FindStringMatch(\"/test\")\nfor _, g := range match.Groups() {\n    fmt.Printf(\"%q \", g.String())\n}\nfmt.Printf(\"%d %q\\n\", match.Index, match)\n//=\u003e \"/test\" \"test\" \"\" 0 \"/test\"\n\nmatch, _ = regexp.FindStringMatch(\"/test/route\")\nfor _, g := range match.Groups() {\n    fmt.Printf(\"%q \", g.String())\n}\nfmt.Printf(\"%d %q\\n\", match.Index, match)\n//=\u003e \"/test/route\" \"test\" \"route\" 0 \"/test/route\"\n```\n\n**Tip:** The prefix is also optional, escape the prefix `\\/` to make it required.\n\nWhen dealing with query strings, escape the question mark (`?`) so it doesn't mark the parameter as optional. Handling unordered data is outside the scope of this library.\n\n```go\nregexp := pathToRegexp.Must(pathToRegexp.PathToRegexp(\"/search/:tableName\\\\?useIndex=true\u0026term=amazing\", nil, nil))\n\nmatch, _ := regexp.FindStringMatch(\"/search/people?useIndex=true\u0026term=amazing\")\nfor _, g := range match.Groups() {\n    fmt.Printf(\"%q \", g.String())\n}\nfmt.Printf(\"%d %q\\n\", match.Index, match)\n//=\u003e \"/search/people?useIndex=true\u0026term=amazing\" \"people\" 0 \"/search/people?useIndex=true\u0026term=amazing\"\n\n// This library does not handle query strings in different orders\nmatch, _ = regexp.FindStringMatch(\"/search/people?term=amazing\u0026useIndex=true\")\nfmt.Println(match)\n//=\u003e \u003cnil\u003e\n```\n\n##### Zero or more\n\nParameters can be suffixed with an asterisk (`*`) to denote a zero or more parameter matches.\n\n```go\nregexp := pathToRegexp.Must(pathToRegexp.PathToRegexp(\"/:foo*\", nil, nil))\n// tokens: [{Name:\"foo\", Prefix:\"/\", Suffix:\"\", Pattern:\"[^\\\\/]+?\", Modifier:\"*\"}]\n\nmatch, _ := regexp.FindStringMatch(\"/\")\nfor _, g := range match.Groups() {\n    fmt.Printf(\"%q \", g.String())\n}\nfmt.Printf(\"%d %q\\n\", match.Index, match)\n//=\u003e \"/\" \"\" 0 \"/\"\n\nmatch, _ = regexp.FindStringMatch(\"/bar/baz\")\nfor _, g := range match.Groups() {\n    fmt.Printf(\"%q \", g.String())\n}\nfmt.Printf(\"%d %q\\n\", match.Index, match)\n//=\u003e \"/bar/baz\" \"bar/baz\" 0 \"/bar/baz\"\n```\n\n##### One or more\n\nParameters can be suffixed with a plus sign (`+`) to denote a one or more parameter matches.\n\n```go\nregexp := pathToRegexp.Must(pathToRegexp.PathToRegexp(\"/:foo+\", nil, nil))\n// tokens: [{Name:\"foo\", Prefix:\"/\", Suffix:\"\", Pattern:\"[^\\\\/]+?\", Modifier:\"+\"}]\n\nmatch, _ := regexp.FindStringMatch(\"/\")\nfmt.Println(match)\n//=\u003e nil\n\nmatch, _ = regexp.FindStringMatch(\"/bar/baz\")\nfor _, g := range match.Groups() {\n    fmt.Printf(\"%q \", g.String())\n}\nfmt.Printf(\"%d %q\\n\", match.Index, match)\n//=\u003e \"/bar/baz\" \"bar/baz\" 0 \"/bar/baz\"\n```\n\n### Match\n\nThe `match` function will return a function for transforming paths into parameters:\n\n```go\nmatch := pathToRegexp.MustMatch(\"/user/:id\", \u0026pathToRegexp.Options{Decode: func(str string, token interface{}) (string, error) {\n    return pathToRegexp.DecodeURIComponent(str)\n}})\n\nmatch(\"/user/123\")\n//=\u003e \u0026pathtoregexp.MatchResult{Path:\"/user/123\", Index:0, Params:map[interface {}]interface {}{\"id\":\"123\"}}\n\nmatch(\"/invalid\") //=\u003e nil\n\nmatch(\"/user/caf%C3%A9\")\n//=\u003e \u0026pathtoregexp.MatchResult{Path:\"/user/caf%C3%A9\", Index:0, Params:map[interface {}]interface {}{\"id\":\"café\"}}\n```\n\n### Parse\n\nThe `Parse` function will return a list of strings and tokens from a path string:\n\n```go\ntokens, _ := pathToRegexp.Parse(\"/route/:foo/(.*)\", nil)\n\nfmt.Printf(\"%#v\\n\", tokens[0])\n//=\u003e \"/route\"\n\nfmt.Printf(\"%#v\\n\", tokens[1])\n//=\u003e pathToRegexp.Token{Name:\"foo\", Prefix:\"/\", Suffix:\"\", Pattern:\"[^\\\\/]+?\", Modifier:\"\"}\n\nfmt.Printf(\"%#v\\n\", tokens[2])\n//=\u003e pathToRegexp.Token{Name:0, Prefix:\"/\", Suffix:\"\", Pattern:\".*\", Modifier:\"\"}\n```\n\n**Note:** This method only works with strings.\n\n### Compile (\"Reverse\" Path-To-RegExp)\n\nThe `Compile` function will return a function for transforming parameters into a valid path:\n\n```go\ntoPath := pathToRegexp.MustCompile(\"/user/:id\", \u0026pathToRegexp.Options{Encode: func(str string, token interface{}) string {\n    return pathToRegexp.EncodeURIComponent(str)\n}})\n\ntoPath(map[string]int{\"id\": 123}) //=\u003e \"/user/123\"\ntoPath(map[string]string{\"id\": \"café\"}) //=\u003e \"/user/caf%C3%A9\"\ntoPath(map[string]string{\"id\": \"/\"}) //=\u003e \"/user/%2F\"\n\ntoPath(map[string]string{\"id\": \":/\"}) //=\u003e \"/user/%3A%2F\"\n\n// Without `encode`, you need to make sure inputs are encoded correctly.\nfalseValue := false\ntoPathRaw := pathToRegexp.MustCompile(\"/user/:id\", \u0026pathToRegexp.Options{Validate: \u0026falseValue})\ntoPathRaw(map[string]string{\"id\": \"%3A%2F\"}); //=\u003e \"/user/%3A%2F\"\ntoPathRaw(map[string]string{\"id\": \":/\"}); //=\u003e \"/user/:/\"\n\ntoPathRepeated := pathToRegexp.MustCompile(\"/:segment+\", nil)\n\ntoPathRepeated(map[string]string{\"segment\": \"foo\"}) //=\u003e \"/foo\"\ntoPathRepeated(map[string][]string{\"segment\": {\"a\", \"b\", \"c\"}}) //=\u003e \"/a/b/c\"\n\ntoPathRegexp := pathToRegexp.MustCompile(\"/user/:id(\\\\d+)\", \u0026pathToRegexp.Options{Validate: \u0026falseValue})\n\ntoPathRegexp(map[string]int{\"id\": 123}) //=\u003e \"/user/123\"\ntoPathRegexp(map[string]string{\"id\": \"123\"}) //=\u003e \"/user/123\"\ntoPathRegexp(map[string]string{\"id\": \"abc\"}) //=\u003e \"/user/abc\"\n\ntoPathRegexp = pathToRegexp.MustCompile(\"/user/:id(\\\\d+)\", nil)\ntoPathRegexp(map[string]string{\"id\": \"abc\"}) //=\u003e panic\n```\n\n**Note:** The generated function will panic on invalid input.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoongo%2Fpath-to-regexp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoongo%2Fpath-to-regexp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoongo%2Fpath-to-regexp/lists"}