compile-time-regular-expressions icon indicating copy to clipboard operation
compile-time-regular-expressions copied to clipboard

Cast ranges to the character type

Open Alcaro opened this issue 8 months ago • 2 comments

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

Alcaro avatar Apr 11 '25 00:04 Alcaro

Version 2: Also fixes \x00-\xFF matching wrong things (there are few bytes <= -1 && >= 0)

Alcaro avatar Apr 11 '25 00:04 Alcaro

Version 3: Also fixes non-range chars in classes, so [a-zñ]+ will match piñata

Alcaro avatar Apr 11 '25 00:04 Alcaro