compile-time-regular-expressions
compile-time-regular-expressions copied to clipboard
Cast ranges to the character type
Fixes #330
Fixes \x80-\xFF not matching high-ascii bytes
#include <ctre.hpp>
#include <regex>
#include <iostream>
int main()
{
const char * b = "knäckebröd";
auto k = ctre::search<R"([\x00-\x7F\x80-\xFF]*)">(b);
std::cout << k.get<0>().to_view() << std::endl;
auto k2 = ctre::search<R"(.*)">(b);
std::cout << k2.get<0>().to_view() << std::endl;
std::regex r{R"([\x00-\x7F\x80-\xFF]*)"};
std::cmatch m;
std::regex_search(b, m, r);
std::cout << m[0] << std::endl;
}
https://godbolt.org/z/h4vxWajxb
Version 2: Also fixes \x00-\xFF matching wrong things (there are few bytes <= -1 && >= 0)
Version 3: Also fixes non-range chars in classes, so [a-zñ]+ will match piñata