Compiletime build up of std::regex

Exagon picture Exagon · Nov 4, 2016 · Viewed 8.8k times · Source

Since I know the regexes at compiletime, and building up a regex is in O(2^m) where m is the length of the regex, I would love to build up the regex at compiletime.

Is this possible with std::regex? (I don't think so, because I don't see any constexpr constructor for basic_regex)

And if not, is there a regex library which can buildup my regexes at compiletime?

Answer

legalize picture legalize · Oct 24, 2017

A CppCon 2017 lightning talk by Hana Dusikova "Regular Expressions Redefined in C++” described an approach to compile-time regular expressions using a user-defined literal for regex strings and a compile-time approach to generating the matching function. The code is on GitHub, but is still experimental and highly fluid at this time. So it seems that compile-time regexes are probably going to appear sometime soon.