{"id":21377190,"url":"https://github.com/odroe/prexp","last_synced_at":"2026-02-08T02:07:00.652Z","repository":{"id":65063685,"uuid":"581631957","full_name":"odroe/prexp","owner":"odroe","description":"Convert the path string to a regular expression, such as `/users/:name` and the like.","archived":false,"fork":false,"pushed_at":"2024-06-05T23:54:39.000Z","size":35,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-07T21:01:21.191Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/odroe.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"odroe","open_collective":"openodroe"}},"created_at":"2022-12-23T19:23:36.000Z","updated_at":"2023-01-31T22:33:50.000Z","dependencies_parsed_at":"2024-11-05T15:36:53.281Z","dependency_job_id":"3c3f3755-0071-4dc9-82b4-a4fd79998c49","html_url":"https://github.com/odroe/prexp","commit_stats":{"total_commits":15,"total_committers":1,"mean_commits":15.0,"dds":0.0,"last_synced_commit":"33ae07a6960049bc5c6a0862bd65250ba09e5788"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/odroe/prexp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/odroe%2Fprexp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/odroe%2Fprexp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/odroe%2Fprexp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/odroe%2Fprexp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/odroe","download_url":"https://codeload.github.com/odroe/prexp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/odroe%2Fprexp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29217763,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-08T00:10:47.190Z","status":"online","status_checked_at":"2026-02-08T02:00:07.642Z","response_time":57,"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-11-22T09:19:25.826Z","updated_at":"2026-02-08T02:07:00.637Z","avatar_url":"https://github.com/odroe.png","language":"Dart","funding_links":["https://github.com/sponsors/odroe","https://opencollective.com/openodroe"],"categories":[],"sub_categories":[],"readme":"# Prexp\n\nPrexp (**P**ath to **re**gular **exp**ression) is a Dart package that converts a path to a regular expression.\n\n```dart\nimport 'package:prexp/prexp.dart';\n\nvoid main() {\n  final String route = r'/users/:name';\n\n  final Prexp prexp = Prexp.fromString(route);\n  print(prexp.hasMatch('/users/odroe')); // true\n\n  final PathMatcher matcher = PathMatcher.fromPrexp(prexp);\n  print(matcher('/users/odroe')); // (PrexpMatch(/users/Seven, {name: Seven}))\n\n  final PathBuilder builder = PathBuilder.fromPath(route);\n  print(builder({'name': 'odroe'})); // /users/odroe\n\n  print(Prexp.parse(\n      route)); // [StringPrexpToken(/users), MetadataPrexpToken({\"name\":\"name\",\"prefix\":\"/\",\"suffix\":\"\",\"pattern\":\"[^\\\\/#\\\\?]+?\",\"modifier\":\"\"}]\n}\n```\n\n## Installation\n\nAdd this to your package's pubspec.yaml file:\n\n```yaml\ndependencies:\n  prexp: latest\n```\n\nOr install it from the command line:\n\n```bash\ndart pub add prexp\n```\n\n## Create a list of `PrexpToken`\n\nThe `Prexp.parse` static utility to create an list of `PrexpToken` from a path.\n\n```dart\nfinal Iterable\u003cPrexpToken\u003e tokens = Prexp.parse('/users/:name');\n```\n\n##### Optional parameters\n\n- `delimiter` - The delimiter between segments. Defaults to `/#?`.\n- `prefixes` - The prefixes to use when parsing a path. Defaults to `./`.\n\n## `Prexp` class\n\n`Prexp` implements the `RegExp` interface and is compatible with `RegExp`. The only difference between `Prexp` and `RegExp` is that `Prexp` contains the parameter source information of path.\n\n```dart\nfinal Prexp prexp = Prexp.fromString('/users/:name');\n\nprint(prexp.hasMatch('/users/odroe')); // true\nprint(prexp is RegExp); // true\nprint(prexp.metadata); // MetadataPrexpToken({\"name\":\"name\",\"prefix\":\"/\",\"suffix\":\"\",\"pattern\":\"[^\\\\/#\\\\?]+?\",\"modifier\":\"\"})\n```\n\n#### Create a `Prexp` from a string\n\n```dart\nfinal Prexp prexp = Prexp.fromString('/users/:name');\n```\n\n#### Create a `Prexp` from a `RegExp`\n\n```dart\nfinal RegExp regexp = ...;\nfinal Prexp prexp = Prexp.fromRegExp(regexp);\n```\n\n#### Create a `Prexp` from a list of `PrexpToken`\n\n```dart\nfinal Iterable\u003cPrexpToken\u003e tokens = Prexp.parse('/users/:name');\nfinal Prexp prexp = Prexp.fromTokens(tokens);\n```\n\n## Path builder\n\nThe `PathBuilder` class is used to build a path from a map of parameters.\n\n#### Create a `PathBuilder` from a path\n\n```dart\nfinal PathBuilder builder = PathBuilder.fromPath('/users/:name');\n\nprint(builder({'name': 'odroe'})); // /users/odroe\n```\n\n#### Create a `PathBuilder` from list of `PrexpToken`\n\n```dart\nfinal Iterable\u003cPrexpToken\u003e tokens = Prexp.parse('/users/:name');\nfinal PathBuilder builder = PathBuilder.fromTokens(tokens);\n\nprint(builder({'name': 'odroe'})); // /users/odroe\n```\n\n## Path matcher\n\nThe `PathMatcher` class is used to match a path against a route.\n\n#### Create a `PathMatcher` from a `Prexp`\n\n```dart\nfinal Prexp prexp = Prexp.fromString('/users/:name');\nfinal PathMatcher matcher = PathMatcher.fromPrexp(prexp);\n\nprint(matcher('/users/odroe')); // (PrexpMatch(/users/odroe, {name: odroe}))\n```\n\n#### Create a `PathMatcher` from a `RegExp`\n\n```dart\nfinal RegExp regexp = ...;\nfinal Iterable\u003cMetadataPrexpToken\u003e metadata = ...;\nfinal PathMatcher matcher = PathMatcher.fromRegExp(regexp, metadata);\n\nprint(matcher('/users/odroe'));\n```\n\n#### Match a path against a route\n\n```dart\n\nfinal PathMatcher matcher = ...;\nfinal Iterable\u003cPrexpMatch\u003e matches = matcher('/users/odroe');\n\nprint(matches); // (PrexpMatch(/users/odroe, {name: odroe}))\n```\n\n\u003e __Note__: If the path does not match the route, the `PathMatcher` returns an empty list.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fodroe%2Fprexp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fodroe%2Fprexp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fodroe%2Fprexp/lists"}