Loading...

Build your own grep

Learn about regex syntax: character classes, quantifiers and more

Start Building
grep
Zig
grep
Go
grep
Haskell
grep
JavaScript
grep
PHP
grep
Python
grep
Rust
grep
C++
grep
C#
grep
Kotlin
grep
Java
grep
Gleam
grep
Odin
grep
TypeScript

This challenge requires a CodeCrafters Membership.

You're welcome to study the full challenge structure and stage instructions for free. A membership is needed for submitting code and viewing solutions.

Want to try a free challenge? Try Build your own Shell — it's free this month.

Regular expressions (or Regexes) are patterns used to match character combinations in strings. In this challenge, you'll build a Regex engine from scratch by recreating grep, a CLI tool for regex-based searching.

Along the way you'll learn about Regex syntax, character classes, quantifiers and more.

Base Stages

Regular expressions (or Regexes) are patterns used to match character combinations in strings. In this challenge, you'll build a Regex engine from scratch by recreating grep, a CLI tool for regex-based searching.

Along the way you'll learn about Regex syntax, character classes, quantifiers and more.

Match a literal character
Very easy
We'd expect a proficient developer to take < 5 minutes to complete this stage.
Match digits
Very easy
We'd expect a proficient developer to take < 5 minutes to complete this stage.
Match word characters
Very easy
We'd expect a proficient developer to take < 5 minutes to complete this stage.
Positive Character Groups
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Negative Character Groups
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Combining Character Classes
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Start of string anchor
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
End of string anchor
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Match one or more times
Hard
We'd expect a proficient developer to take more than 1 hour to complete this stage.
Match zero or one times
Hard
We'd expect a proficient developer to take more than 1 hour to complete this stage.
Wildcard
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Alternation
Hard
We'd expect a proficient developer to take more than 1 hour to complete this stage.

Backreferences

In this challenge extension, you'll add support for backreferences to your Grep implementation.

Along the way, you'll learn about how capture groups and backreferences work.

Single Backreference
Hard
We'd expect a proficient developer to take more than 1 hour to complete this stage.
Multiple Backreferences
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Nested Backreferences
Hard
We'd expect a proficient developer to take more than 1 hour to complete this stage.

File Search

In this challenge extension, you'll add support for searching files.

Along the way, you'll learn about how to implement efficient file I/O, directory traversal and pattern matching on file contents.

Search a single-line file
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Search a multi-line file
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Search multiple files
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Recursive search
Hard
We'd expect a proficient developer to take more than 1 hour to complete this stage.

Quantifiers

In this challenge extension, you'll add support for quantifiers to your Grep implementation.

Along the way, you'll learn about how to implement the * quantifier (zero or more), and bounded quantifiers.

Match zero or more times
Hard
We'd expect a proficient developer to take more than 1 hour to complete this stage.
Match exactly n times
Hard
We'd expect a proficient developer to take more than 1 hour to complete this stage.
Match at least n times
Hard
We'd expect a proficient developer to take more than 1 hour to complete this stage.
Match between n and m times
Hard
We'd expect a proficient developer to take more than 1 hour to complete this stage.