Skip to content

Grepper is a regular expression (Regex) engine built from scratch using C++, capable of searching through text with support for various Regex patterns and features.

Notifications You must be signed in to change notification settings

Ashfinn/Grepper

Repository files navigation

Grepper

progress-banner

This repository contains an implementation of the grep tool built in C++ as part of the Codecrafters "Build Your Own Grep" Challenge. The project focuses on building a regular expression (Regex) engine from scratch, capable of searching through text with support for various Regex patterns and features.

Forks Stargazers Issues

About The Project

This project is an attempt to implement grep, a command-line utility for searching text using regular expressions, in C++. Along the way, we will dive into the workings of regex syntax, character classes, quantifiers, and more. By the end of the challenge, you will have a deeper understanding of how Regex works under the hood and be able to search and match patterns in text just like the real grep tool.

Key Features:

  • Matching literal characters
  • Supporting various regex features such as character classes, anchors, quantifiers, and more
  • Backreference support
  • Regex alternation
  • Wildcard matches

(back to top)

Built With

The project is developed using:

  • C++: The core language for implementing our custom grep functionality.
  • POSIX standard: For guiding the implementation to match grep's expected behavior.

(back to top)

Getting Started

To get started with building and running your own grep implementation, follow the instructions below.

Prerequisites

Make sure you have the following installed:

  • GCC or any other C++ compiler.
  • Make (optional, for build automation).

Repository Setup

  1. Clone the repository:

    git clone https://github.com/your_username/grep_cpp.git
  2. Navigate to the project directory:

    cd grep_cpp
  3. Compile the project:

    g++ -o grep_cpp main.cpp
  4. Run the program with a test file:

    ./grep_cpp "pattern" test_file.txt

(back to top)

Features

Match a Literal Character

The most basic functionality of grep is to search for a literal string within a text.

Match Digits

Our implementation supports matching digits (e.g., \d).

Match Alphanumeric Characters

Match alphanumeric characters using character classes.

Positive Character Groups

We can match specific groups of characters like [a-zA-Z].

Negative Character Groups

Supports negation in character groups, like [^a-z].

Combining Character Classes

You can combine character classes and patterns for complex matching.

Anchors (Start and End of String)

Use the ^ (start of string) and $ (end of string) anchors to match text at the beginning or end of a string.

Quantifiers

  • +: Match one or more times
  • ?: Match zero or one times

Wildcards

Supports . wildcard to match any single character.

Alternation

Supports the | operator to match alternative patterns (e.g., abc|xyz).

Backreferences

  • Single Backreference: Allows matching repeated patterns.
  • Multiple Backreferences: Matches more complex repeated groups.
  • Nested Backreferences: Supports matching nested patterns using backreferences.

(back to top)

Roadmap

  • Match literal characters
  • Implement digit matching and alphanumeric character groups
  • Add support for character groups (positive and negative)
  • Implement anchors (start/end of string)
  • Add quantifiers and alternation support
  • Implement backreferences
  • Optimize regex matching algorithm for performance

(back to top)

Contributing

Contributions are welcome! If you'd like to contribute to the project, feel free to fork the repo and submit a pull request.

  1. Fork the project.
  2. Create your feature branch (git checkout -b feature/newFeature).
  3. Commit your changes (git commit -m 'Add some feature').
  4. Push to the branch (git push origin feature/newFeature).
  5. Open a pull request.

(back to top)

License

Distributed under the MIT License. See LICENSE for more information.

(back to top)

Contact

Your Name - @Linkedin - obidur.shawal@gmail.com

Project Link: https://github.com/Ashfinn/grepper

(back to top)

About

Grepper is a regular expression (Regex) engine built from scratch using C++, capable of searching through text with support for various Regex patterns and features.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published