{"id":16595498,"url":"https://github.com/tako8ki/regexm","last_synced_at":"2025-03-16T21:30:40.234Z","repository":{"id":53436351,"uuid":"327854674","full_name":"TaKO8Ki/regexm","owner":"TaKO8Ki","description":"A Rust macro for writing regex pattern matching.","archived":false,"fork":false,"pushed_at":"2021-03-30T16:05:46.000Z","size":39,"stargazers_count":49,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-13T04:47:03.901Z","etag":null,"topics":["macro","pattern-matching","regex","rust"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/regexm","language":"Rust","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/TaKO8Ki.png","metadata":{"files":{"readme":"README.md","changelog":null,"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},"funding":{"github":"TaKO8Ki"}},"created_at":"2021-01-08T09:19:08.000Z","updated_at":"2025-02-07T10:51:36.000Z","dependencies_parsed_at":"2022-09-05T01:11:11.879Z","dependency_job_id":null,"html_url":"https://github.com/TaKO8Ki/regexm","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TaKO8Ki%2Fregexm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TaKO8Ki%2Fregexm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TaKO8Ki%2Fregexm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TaKO8Ki%2Fregexm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TaKO8Ki","download_url":"https://codeload.github.com/TaKO8Ki/regexm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243830933,"owners_count":20354852,"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","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":["macro","pattern-matching","regex","rust"],"created_at":"2024-10-11T23:50:36.824Z","updated_at":"2025-03-16T21:30:39.953Z","avatar_url":"https://github.com/TaKO8Ki.png","language":"Rust","funding_links":["https://github.com/sponsors/TaKO8Ki"],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n # regexm\n \n A Rust macro for writing regex pattern matching.\n\n [![github workflow status](https://img.shields.io/github/workflow/status/TaKO8Ki/regexm/CI/main)](https://github.com/TaKO8Ki/regexm/actions) [![crates](https://img.shields.io/crates/v/regexm.svg?logo=rust)](https://crates.io/crates/regexm) [![docs](https://img.shields.io/badge/docs-regexm-8da0cb?labelColor=555555\u0026logo=rust)](https://docs.rs/regexm)\n\n [Usage](##Usage) | [Examples](examples) | [Docs](https://docs.rs/regexm)\n\n\u003c/div\u003e\n\n## Features\n\n- Capture groups\n\n## Dependencies\n\n```toml\n[dependencies]\nregex = \"1\"\nregexm = \"0.2.1\"\n```\n\n## Usage\n\n### Simple pattern matching\n\n```rust\nfn main() {\n    let text1 = \"2020-01-01\";\n    regexm::regexm!(match text1 {\n        r\"^\\d{4}$\" =\u003e println!(\"yyyy\"),\n        r\"^\\d{4}-\\d{2}$\" =\u003e println!(\"yyyy-mm\"),\n        // block\n        r\"^\\d{4}-\\d{2}-\\d{2}$\" =\u003e {\n            let yyyy_mm_dd = \"yyyy-mm-dd\";\n            println!(\"{}\", yyyy_mm_dd);\n        }\n        _ =\u003e println!(\"default\"),\n    });\n}\n```\n\nOutput:\n\n```sh\nyyyy-mm-dd\n```\n\nthe generated code will be the following:\n\n```rust\nfn main() {\n    let text1 = \"2020-01-01\";\n    if regex::Regex::new(r\"^\\d{4}$\").unwrap().is_match(text1) {\n        println!(\"yyyy\")\n    } else if regex::Regex::new(r\"^\\d{4}-\\d{2}$\").unwrap().is_match(text1) {\n        println!(\"yyyy-mm\")\n    } else if regex::Regex::new(r\"^\\d{4}-\\d{2}-\\d{2}$\")\n        .unwrap()\n        .is_match(text1)\n    {\n        let yyyy_mm_dd = \"yyyy-mm-dd\";\n        println!(\"{}\", yyyy_mm_dd);\n    } else {\n        println!(\"default\")\n    };\n}\n```\n\n\n### Let match\n\n```rust\nfn main() {\n    let text2 = \"foo\";\n    let foo = regexm::regexm!(match text2 {\n        r\"^\\d{4}-\\d{2}-\\d{2}$\" =\u003e \"yyyy-mm-dd\",\n        r\"^\\d{4}-\\d{2}$\" =\u003e \"yyyy-mm\",\n        // block\n        r\"^\\d{4}-\\d{2}-\\d{2}$\" =\u003e {\n            let yyyy_mm_dd = \"yyyy-mm-dd\";\n            yyyy_mm_dd\n        }\n        _ =\u003e \"default\",\n    });\n    println!(\"{}\", foo);\n}\n```\n\nOutput:\n\n```sh\ndefault\n```\n\nthe generated code will be the following:\n\n```rust\nfn main() {\n    let text2 = \"foo\";\n    let foo = if regex::Regex::new(r\"^\\d{4}-\\d{2}-\\d{2}$\")\n        .unwrap()\n        .is_match(text2)\n    {\n        \"yyyy-mm-dd\"\n    } else if regex::Regex::new(r\"^\\d{4}-\\d{2}$\").unwrap().is_match(text2) {\n        \"yyyy-mm\"\n    } else if regex::Regex::new(r\"^\\d{4}-\\d{2}-\\d{2}$\")\n        .unwrap()\n        .is_match(text2)\n    {\n        let yyyy_mm_dd = \"yyyy-mm-dd\";\n        yyyy_mm_dd\n    } else {\n        \"default\"\n    };\n    println!(\"{}\", foo);\n}\n```\n\n### Capture Groups\n\n```rust\nfn main() {\n    let text1 = \"2020-01-02\";\n    regexm::regexm!(match text1 {\n        // capture groups\n        captures(r\"^(\\d{4})-(\\d{2})-(\\d{2})$\") =\u003e |caps| println!(\n            \"year: {}, month: {}, day: {}\",\n            caps.get(1).map_or(\"\", |m| m.as_str()),\n            caps.get(2).map_or(\"\", |m| m.as_str()),\n            caps.get(3).map_or(\"\", |m| m.as_str())\n        ),\n        _ =\u003e println!(\"default\"),\n    });\n}\n```\n\nOutput:\n\n```sh\n2020\n01\n02\n```\n\nthe generated code will be the following:\n\n```rust\nfn main() {\n    let text1 = \"2020-01-02\";\n    if regex::Regex::new(r\"^(\\d{4})-(\\d{2})-(\\d{2})$\")\n        .unwrap()\n        .is_match(text1)\n    {\n        let closure = |caps: regex::Captures| {\n            println!(\n                \"year: {}, month: {}, day: {}\",\n                caps.get(1).map_or(\"\", |m| m.as_str()),\n                caps.get(2).map_or(\"\", |m| m.as_str()),\n                caps.get(3).map_or(\"\", |m| m.as_str())\n            )\n        };\n        closure(\n            regex::Regex::new(r\"^(\\d{4})-(\\d{2})-(\\d{2})$\")\n                .unwrap()\n                .captures(text1)\n                .unwrap(),\n        )\n    } else {\n        println!(\"default\")\n    };\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftako8ki%2Fregexm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftako8ki%2Fregexm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftako8ki%2Fregexm/lists"}