A C++ library for compile-time regular expression matching, searching, and capturing with PCRE-like syntax.
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.
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.
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.
Compile Time Regular Expression in C++
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
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.
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.
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.
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.
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.
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 functionality needs additional headers (<ctre-unicode.hpp>) and careful setup, such as casting for output, adding friction compared to basic usage without Unicode.