libc++ / libstdc++ : Same regex, different results

251 views Asked by At

I've got the follwing code, which prints '6' when using libstdc++ and '7' when using libc++ (which is the length of a regex match).

In my opinion the libstdc++ behaviour is correct but I am not sure.

More importantly: what can I do to ensure the same behaviour on both libraries ?

#include <regex>
#include <string>
#include <iostream>

int main()
{
    std::regex reg{R"_(\{(-?[0-9]+)\.\.(-?[0-9]+)})_"};
    std::string str = "{-2..2}";

    std::regex_iterator<std::string::iterator> rit (str.begin(), str.end(), reg);
    std::regex_iterator<std::string::iterator> rend;

    std::cout << rit->length();
}
0

There are 0 answers