Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. C/C++
  3. CTRE

CTRE

Apache-2.0C++v3.11.0

A C++ library for compile-time regular expression matching, searching, and capturing with PCRE-like syntax.

Visit WebsiteGitHubGitHub
3.8k stars206 forks0 contributors

What is CTRE?

Compile Time Regular Expressions (CTRE) is a C++ library that enables regular expression matching, searching, and capturing to be executed at compile time rather than runtime. It provides a PCRE-like syntax and allows developers to validate and process string patterns during compilation, resulting in zero-overhead regex operations for fixed patterns. The library supports Unicode, named captures, and range-based iteration over matches.

Target Audience

C++ developers working on performance-critical applications, compilers, or tools that require efficient string parsing and validation, particularly those using modern C++17/20 features.

Value Proposition

Developers choose CTRE for its ability to eliminate runtime regex overhead by shifting pattern matching to compile time, offering PCRE compatibility without sacrificing performance, and providing a clean, modern API with support for structured bindings and Unicode.

Overview

Compile Time Regular Expression in C++

Use Cases

Best For

  • Validating string formats at compile time in C++ projects
  • Building high-performance lexers or parsers with regex patterns
  • Extracting structured data (like dates or numbers) from strings with zero runtime cost
  • Implementing Unicode-aware text processing in C++
  • Creating compile-time regex-based DSLs or template metaprogramming utilities
  • Replacing runtime regex libraries in performance-sensitive C++ code

Not Ideal For

  • Projects using compilers older than GCC 9, Clang 14, or MSVC 16.11, as CTRE requires modern C++ support
  • Applications needing dynamic regex patterns generated at runtime, since CTRE excels only with fixed patterns validated at compile time
  • Teams requiring full PCRE feature sets including callouts, conditional patterns, or unicode grapheme clusters, which CTRE explicitly omits
  • Environments where compile-time regex errors could disrupt workflows, such as when patterns are user-provided or frequently changed

Pros & Cons

Pros

Zero Runtime Overhead

Patterns are matched at compile time for fixed regex, eliminating performance costs, as shown in examples where matches are evaluated in constexpr contexts with no runtime penalty.

PCRE Syntax Familiarity

Supports most PCRE features like capturing, back-references, and Unicode properties, making it easy for developers to transition from libraries like PCRE or std::regex.

Modern C++ Integration

Seamlessly works with structured bindings and range-based APIs, allowing clean code like auto [whole, year, month, day] = ctre::match<"...">(input) for easy data extraction.

Flexible Syntax Options

Offers multiple syntaxes across C++17 and C++20, such as template UDL or cNTTP, accommodating different compiler support levels, as detailed in the README's compiler compatibility section.

Cons

Incomplete PCRE Support

Lacks several PCRE features like callouts, conditional patterns, and unicode grapheme clusters, as admitted in the README's list of exceptions, limiting its use for advanced regex scenarios.

Compiler and Version Lock-in

Requires specific compiler versions (e.g., GCC 9+, Clang 14+) and some syntaxes depend on extensions or macros, reducing portability and increasing setup complexity for heterogeneous teams.

Unicode Support Overhead

Unicode functionality needs additional headers (<ctre-unicode.hpp>) and careful setup, such as casting for output, adding friction compared to basic usage without Unicode.

Frequently Asked Questions

Quick Stats

Stars3,826
Forks206
Contributors0
Open Issues86
Last commit13 days ago
CreatedSince 2016

Tags

#parsing#unicode#constexpr#template-metaprogramming#regular-expression#cpp17#lexer#cplusplus#awesome#pcre#cpp20#regular-expressions#header-only#performance#compile-time

Built With

c
c++20
C
C++17

Links & Resources

Website

Included in

C/C++70.6k
Auto-fetched 17 hours ago

Related Projects

HyperscanHyperscan

High-performance regular expression matching library

Stars5,444
Forks808
Last commit1 day ago
OnigurumaOniguruma

regular expression library

Stars2,525
Forks351
Last commit1 year ago
VectorscanVectorscan

A portable fork of the high-performance regular expression matching library

Stars713
Forks88
Last commit21 days ago
sregexsregex

A non-backtracking NFA/DFA-based Perl-compatible regex engine matching on large data streams

Stars629
Forks105
Last commit4 years ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub