Mac 和 Linux 机器之间的正则表达式兼容性问题
compatibility issues with regex between Mac and Linux machines
原始问题:“我使用 Xcode 8 最新的 LLVM 8 编译器(clang 8/3.8?)在我的 Mac 上开发了一个程序,它大量使用了 c++ 中的正则表达式14. 当 linux 上的 运行 时,我无法让我的代码给我正确的输出。似乎有一些我不知道的正则表达式兼容性问题。
我该如何解决这个问题?
像这样将 std:: 换成 boost::
//using std::regex_replace;
using boost::regex_replace;
using boost::sregex_iterator;
//using std::sregex_iterator;
//using std::smatch;
using boost::smatch;
//using std::regex;
using boost::regex;
并添加
#include <boost/regex.hpp>
(我已经在使用 boost::filesystem,所以大多数 headers/libraries 已经是 included/linked)。我想这不是很明显,但应该注意的是,这两个功能在 Boost 中都有更稳定的父级(至少在 boost::filesystem 的情况下,C++ 中的 'experimental' 版本实际上只是 Boost ).
所以,这解决了所有兼容性问题,因为我保证在我的 Mac 和 Linux 机器上都遵循升压规范。
如果有这个答案,我可以节省 5 个小时...也许现在它可以为您节省 5 个小时。
原始问题:“我使用 Xcode 8 最新的 LLVM 8 编译器(clang 8/3.8?)在我的 Mac 上开发了一个程序,它大量使用了 c++ 中的正则表达式14. 当 linux 上的 运行 时,我无法让我的代码给我正确的输出。似乎有一些我不知道的正则表达式兼容性问题。
我该如何解决这个问题?
像这样将 std:: 换成 boost::
//using std::regex_replace;
using boost::regex_replace;
using boost::sregex_iterator;
//using std::sregex_iterator;
//using std::smatch;
using boost::smatch;
//using std::regex;
using boost::regex;
并添加
#include <boost/regex.hpp>
(我已经在使用 boost::filesystem,所以大多数 headers/libraries 已经是 included/linked)。我想这不是很明显,但应该注意的是,这两个功能在 Boost 中都有更稳定的父级(至少在 boost::filesystem 的情况下,C++ 中的 'experimental' 版本实际上只是 Boost ).
所以,这解决了所有兼容性问题,因为我保证在我的 Mac 和 Linux 机器上都遵循升压规范。
如果有这个答案,我可以节省 5 个小时...也许现在它可以为您节省 5 个小时。