A lightweight regular expression engine implemented in Modern C++ using std::string_view and recursion. This project demonstrates how to implement a basic regex engine from scratch, supporting:
^β anchor to start of string$β anchor to end of string.β match any single character*β match zero or more of the preceding character
- β
Anchors (
^,$) - β
Wildcards (
.) - β
Zero or more repetition (
*) - β
Efficient string slicing with
std::string_view - β Zero dependencies
- Entry point for matching a regex against a given text.
- Handles the
^anchor and attempts match from every position if not anchored.
- Handles matching from the current point in the string.
- Processes
.,$, and character-by-character match.
- Implements the logic for
*, matching zero or more of the preceding character.
| Pattern | Meaning |
|---|---|
^abc |
Match only if abc is at start |
abc$ |
Match only if abc is at end |
a.c |
Match a + any character + c |
ab*c |
Match a + zero or more b + c |
^a.*c$ |
Match from start to end |
This project is based on the classic example from "The Practice of Programming"
by Brian Kernighan and Rob Pike, rewritten in modern C++ for readability and performance.