regex - C++ (C++11) regular expressions differences on OS X and Linux -
this question has answer here:
i'm trying code work on both os x , linux same. code below compiled clang++ --std=c++11 regextest.cpp
#include <regex> #include <iostream> int main() { std::string str = "/api/asd/"; std::string pattern = "/api/(.*)/"; std::cout << "starting matching" << std::endl; std::smatch matches; if (std::regex_match(str, matches, std::regex(pattern, std::regex::egrep))) { std::cout << "found match!" << std::endl; std::cout << "all matches: "; (auto& : matches) std::cout << << ", "; std::cout << std::endl; } return 0; }
on os x, result of running code is:
starting matching found match! matches: /api/asd/, asd,
on linux, on other hand (gentoo, libstdc++ 3.3)
starting matching found match! matches: /api/asd/, /asd/, //
how match /api/
on linux? why?
additionally, trying use pattern /api/([^/])
fails in linux , matches nothing works in os x.
i've tried many combinations of match types, (basic, extended, grep, egrep, awk) escaped , unescaped (
, )
(depending on match type) , nothing produces expected results on linux.
as suggested comments, issue solved upgrading gcc 4.9. (~amd64 flag required on gentoo).
Comments
Post a Comment