{"id":22701894,"url":"https://github.com/saphereye/gregex","last_synced_at":"2025-11-17T16:06:17.380Z","repository":{"id":222832523,"uuid":"758435211","full_name":"Saphereye/gregex","owner":"Saphereye","description":"Provides a regular expression engine that uses a Nondeterministic finite automaton to simulate the regular expression","archived":false,"fork":false,"pushed_at":"2024-07-04T06:42:16.000Z","size":59,"stargazers_count":1,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-10T16:52:02.770Z","etag":null,"topics":["nfa","regex"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/gregex","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/Saphereye.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-16T10:12:01.000Z","updated_at":"2024-07-04T06:43:44.000Z","dependencies_parsed_at":"2024-02-16T14:30:38.692Z","dependency_job_id":"859e6ec7-d20b-4035-9c14-23e7f1730bd6","html_url":"https://github.com/Saphereye/gregex","commit_stats":null,"previous_names":["saphereye/gregex"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Saphereye%2Fgregex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Saphereye%2Fgregex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Saphereye%2Fgregex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Saphereye%2Fgregex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Saphereye","download_url":"https://codeload.github.com/Saphereye/gregex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240474226,"owners_count":19807281,"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":["nfa","regex"],"created_at":"2024-12-10T07:11:00.393Z","updated_at":"2025-11-17T16:06:17.373Z","avatar_url":"https://github.com/Saphereye.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gregex ![crates.io](https://img.shields.io/crates/v/gregex.svg)\n\nGregex is a powerful regular expression library that compiles regex patterns to Non-deterministic Finite Automata (NFA) at compile-time using Glushkov's construction algorithm. Write regex patterns as strings and let Rust's procedural macros do the rest!\n\n## Features\n\n- **String-based regex parsing**: Write natural regex syntax like `regex!(\"(a|b)+\")`\n- **Compile-time construction**: Zero runtime regex parsing overhead\n- **Type-safe**: Leverages Rust's procedural macros for safety\n- **NFA-based matching**: Uses Glushkov's construction for efficient matching\n- **Rich operator support**: `*`, `+`, `?`, `|`, concatenation, and grouping\n\n## Quick Start\n\nAdd gregex to your `Cargo.toml`:\n\n```bash\ncargo add --git https://github.com/Saphereye/gregex\n```\n\n### Simple Example\n\n```rust\nuse gregex::*;\n\nfn main() {\n    // Natural regex syntax - parsed at compile time!\n    let pattern = regex!(\"(a|b)+c\");\n    \n    // Use standard regex API methods\n    assert!(pattern.is_match(\"abc\"));      // Find pattern anywhere\n    assert!(pattern.is_match(\"prefix_abc_suffix\"));\n    assert_eq!(pattern.find(\"xabcy\"), Some((1, 4)));  // Get match position\n}\n```\n\n## API Methods\n\nGregex provides a standard regex API similar to Rust's `regex` crate:\n\n| Method | Description | Example |\n|--------|-------------|---------|\n| `is_match(text)` | Check if pattern exists in text | `pattern.is_match(\"hello\")` |\n| `find(text)` | Get first match position | `pattern.find(\"text\")` → `Some((start, end))` |\n| `find_iter(text)` | Iterator over all matches | `pattern.find_iter(\"text\").collect()` |\n\n## Regex Syntax Reference\n\nWhen using string-based syntax with `regex!(\"...\")`, the following operators are supported:\n\n| Syntax | Description | Example | Matches |\n|--------|-------------|---------|---------|\n| `a`, `b`, `c` | Literal characters | `regex!(\"abc\")` | \"abc\" |\n| `ab` | Concatenation (implicit) | `regex!(\"hello\")` | \"hello\" |\n| `a\\|b` | Alternation (OR) | `regex!(\"a\\|b\")` | \"a\" or \"b\" |\n| `a*` | Kleene star (zero or more) | `regex!(\"a*\")` | \"\", \"a\", \"aa\", ... |\n| `a+` | Plus (one or more) | `regex!(\"a+\")` | \"a\", \"aa\", \"aaa\", ... |\n| `a?` | Question (zero or one) | `regex!(\"a?\")` | \"\" or \"a\" |\n| `(...)` | Grouping for precedence | `regex!(\"(ab)+\")` | \"ab\", \"abab\", ... |\n\n### Wildcard Patterns\n\n**Note**: The `.` wildcard (match any character) and `.*` patterns are not currently supported in the parser. However:\n- Use `(a|b|c)*` to match specific character sets with repetition\n- Use alternation `(a|b|c)+` for one-or-more of specific characters  \n- The `is_match()` method finds patterns anywhere in text, so `pattern.is_match()` behaves similarly to `.*pattern.*` in standard regex\n\n**Future Enhancement**: Full wildcard support (`.` and `\\w`, `\\d`, etc.) is planned for a future version.\n\n\n## Usage Examples\n\n### 1. String-Based Syntax (Recommended)\n\nThe most natural and recommended way to use Gregex:\n\n```rust\nuse gregex::*;\n\n// Simple patterns with new API\nlet pattern = regex!(\"a+@b+\");\nassert!(pattern.is_match(\"aaa@bbb\"));\nassert!(pattern.is_match(\"prefix_aa@bb_suffix\"));\n\n// Complex patterns with operators\nlet identifier = regex!(\"(a|b)(a|b|c)*\");\nassert!(identifier.is_match(\"abc\"));\nassert!(identifier.is_match(\"bca\"));\n\n// Find match positions\nlet pattern = regex!(\"a+b?c*\");\nif let Some((start, end)) = pattern.find(\"xyzaabccxyz\") {\n    println!(\"Found match from {} to {}\", start, end);\n}\n\n// Nested grouping\nlet nested = regex!(\"((a|b)+c)*\");\nassert!(nested.is_match(\"acbc\"));\n```\n\n## Examples\n\nRun the included examples to see gregex in action:\n\n### Basic Operator Examples\n\nThese examples demonstrate individual regex operators:\n\n```bash\n# Basic concatenation (matching \"abc\")\ncargo run --example 01_basic_concatenation\n\n# Alternation/OR operator (a|b|c)\ncargo run --example 02_alternation\n\n# Kleene star - zero or more (a*)\ncargo run --example 03_kleene_star\n\n# Plus operator - one or more (a+)\ncargo run --example 04_plus_operator\n\n# Question operator - zero or one (a?)\ncargo run --example 05_question_operator\n\n# Grouping and operator precedence\ncargo run --example 06_grouping_and_precedence\n```\n\n### Advanced Examples\n\n```bash\n# Complete API methods demonstration\ncargo run --example 07_api_methods\n\n# Compile-time NFA construction verification\ncargo run --example 08_compile_time_construction\n```\n\n### Use Case Examples\n\nReal-world applications demonstrating practical pattern matching:\n\n```bash\n# Validate programming identifiers\ncargo run --example usecase_identifier_validator\n\n# Match URL-like paths\ncargo run --example usecase_simple_url_matcher\n\n# Search for patterns in text\ncargo run --example usecase_text_search\n```\n\n## How It Works\n\nGregex uses Glushkov's construction algorithm to convert regular expressions into NFAs:\n\n1. **Linearization**: Each symbol in the regex is assigned a unique index\n2. **Set Construction**: Computes prefix, suffix, factors, and nullability sets\n3. **NFA Generation**: Constructs the NFA based on these sets\n4. **Simulation**: Runs the input string through the NFA to determine if it matches\n\nThis approach generates NFAs with states equal to the number of terminals plus one, making it efficient for pattern matching.\n\n## Testing\n\nRun the comprehensive test suite:\n\n```bash\ncargo test --all\n```\n\n## License\n\nMIT License - see [LICENSE](LICENSE) for details.\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaphereye%2Fgregex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaphereye%2Fgregex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaphereye%2Fgregex/lists"}