A grep-like CLI tool written in Rust, featuring a custom-built regex engine implemented from scratch.
This project does NOT use Rust's built-in regex crate. Instead, it implements:
- Regex parser
- AST representation
- Backtracking matcher
- Capture groups and backreferences
- Quantifiers (
*,+,?,{n},{n,m},{n,}) - Alternation (
|) - Character classes (
[abc],[^abc]) - Anchors (
^,$) - CLI compatible with basic
grepusage
Supported syntax:
| Feature | Example |
|---|---|
| Literal | abc |
| Wildcard | . |
| Digit class | \d |
| Word class | \w |
| Character class | [abc] |
| Negative class | [^abc] |
| Quantifiers | a*, a+, a?, a{3}, a{2,5} |
| Grouping | (abc) |
| Alternation | `(a |
| Backreference | (ab)\1 |
| End anchor | $ |
| Start anchor | ^ |
| Option | Description |
|---|---|
-E pattern |
regex pattern (required) |
-o |
print only matches |
-r |
recursive search |
--color=always |
force color |
--color=never |
disable color |
--color=auto |
color if terminal |
Search stdin:
echo "hello123" | cargo run -- -E "\d+"This project was built as part of the CodeCrafters challenge, which focuses on implementing real-world systems from scratch.
The goal was to understand how regex engines work internally, including parsing, AST construction, and backtracking match algorithms, without relying on external regex libraries.
MIT License — see LICENSE file for details.