boost::regex 和std::regex之间的不一致?
Inconsistency between boost::regex and std::regex?
我正在使用boost::regex
编码,似乎它与 C++11 的std::regex
没有给出相同的结果。
请考虑以下简单代码:
#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版本(GCC 5.4,wandbox中的GCC 8.0,MSVC 2015(提供了Result : abc.txt
但是,带有Boost 1.64版本的C++03(wandbox中的GCC 8.0(提供了Result : abc.txt
我也试图::regex::extended
而不是::regex::ECMAScript
但它们是一样的。
boost::regex
和std::regex
是否存在未知的MAGIC不一致之处?
我不确定这是不是故意的。 有一个boost::regex_constants::format_literal
可以用作regex_replace
的第四个参数,然后你可以得到与 std::regex_replace 相同的结果。但是标准 c++ 库中没有format_literal
。
相关文章:
- 大于65535的C++数组[size]引发不一致的溢出
- 在 C++(和 C)中进行类型转换时明显不一致
- 填充上编译器生成的复制构造函数之间的不一致
- 犰狳的 print() 方法和 cout 在从 Rcpp 调用时顺序不一致
- CreateDIBSection为同一图像返回不一致的位图位值
- 在 Qml 中从 QSqlTableModel 中删除单行时视图不一致
- 模板参数推导不一致
- 声明中不一致的no是否违反ODR?
- 如何删除分支因子不一致的树,最大为 30,40
- 从 C++ 函数与 Python 函数返回的不一致值用于偏斜正态分布
- 从 C 字符串构造 std::string 与从另一个 std::string 构造 std::string 不一致
- 这种比较是否不一致(或者存在其他问题)?
- 以下可变参数模板行为是否不一致?
- 如何修复我的链表读数不一致的问题?
- 在C++17中,为什么类模板和函数模板的指针类型推导明显不一致
- void 函数中的指针参数返回不一致的值
- 如何查找导致结果不一致的代码
- 跨平台 mySQL 与字符集不一致
- boost::regex 和std::regex之间的不一致?
- boost::regex和std::regex之间的不一致