Skip to content

arrowten/Regular-Expression-matcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” Mini Regex Matcher in Modern C++

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

πŸš€ Features

  • βœ… Anchors (^, $)
  • βœ… Wildcards (.)
  • βœ… Zero or more repetition (*)
  • βœ… Efficient string slicing with std::string_view
  • βœ… Zero dependencies

🧠 Internals

match()

  • Entry point for matching a regex against a given text.
  • Handles the ^ anchor and attempts match from every position if not anchored.

match_here()

  • Handles matching from the current point in the string.
  • Processes ., $, and character-by-character match.

match_star()

  • Implements the logic for *, matching zero or more of the preceding character.

πŸ§ͺ Supported Regex Grammar

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

πŸ“š Inspired By

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages