Skip to content
Advertisement

compatibility issues with regex between Mac and Linux machines

Original Question: “I developed a program on my Mac using Xcode 8’s latest LLVM 8 compiler (clang 8/3.8?) which made heavy use of regular expressions out of c++14. I was then unable to get my code to give me the correct output when running on linux. There seem to be some regular expression compatibility issues that I am unaware of.

How can I resolve this ?

Advertisement

Answer

Swap out std:: for boost:: like so

//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;

and add

#include <boost/regex.hpp> 

(I was already using boost::filesystem, so most of the headers/libraries were already included/linked). I guess it’s not immediately apparent, but it should be noted that both of these features have more-stable parents in Boost (at least in the case of boost::filesystem, the ‘experimental’ version in C++ is actually just Boost).

So, that handled any compatibility issues because I was guaranteed to be following boost specifications on both my Mac and Linux machines.

Having this answer would’ve saved me 5 hours… Maybe now it’ll save you 5 hours.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement