jeudi 13 juillet 2017

Inconsistency between boost::regex and std::regex?

I'm coding with boost::regex and it seems like it doesn't give same result with C++11's std::regex.

Consider Following simple code:

#include <string>
#include <iostream>
#if defined(_MSC_VER) || (__cplusplus >= 201103L)
#include <regex>
#else // defined(_MSC_VER) || (__cplusplus >= 201103L)
#include <boost/regex.hpp>
#endif // defined(_MSC_VER) || (__cplusplus >= 201103L)

namespace {
#if defined(_MSC_VER) || (__cplusplus >= 201103L)
using std::regex;
using std::regex_replace;
#else // defined(_MSC_VER) || (__cplusplus >= 201103L)
using boost::regex;
using boost::regex_replace;
#endif // defined(_MSC_VER) || (__cplusplus >= 201103L)
} // namespace

int main() {
    std::string input = "abc.txt";
    ::regex re("[.]", ::regex::extended);

    std::string output = ::regex_replace(input, re, "\\.");

    std::cout << "Result : " << output << "\n";
    return 0;
}

C++11 Version (GCC 5.4, GCC 8.0 in wandbox, MSVC 2015) gives Result : abc\.txt

However, C++03 with Boost 1.64 version (GCC 8.0 in wandbox) gives Result : abc.txt

I also tried to ::regex::extended instead of ::regex::ECMAScript but they are same.

Is there are unknown MAGIC inconsistencies from boost::regex and std::regex?

Aucun commentaire:

Enregistrer un commentaire