title: std::regex behaves differently between Mac OS and Linux
body: <p>I was struggling with unicode regex matching with C++ <code>std::regex</code>. I found that the <code>std::regex_search</code> function may return different values on Mac OS and Linux.</p>
  <p>Here is the sample code.</p>
  <pre><code>#include &quot;string&quot;
  #include &quot;regex&quot;
  #include &quot;iostream&quot;
  #include &quot;locale&quot;
  
  void regex_test() {
    std::locale::global(std::locale(&quot;en_US.UTF-8&quot;));
    {
      std::wstring str(L&quot;水&quot;);
      std::wregex re(L&quot;\\w+&quot;, std::regex::collate);
  
      if (std::regex_search(str, re)) {
        std::cout &lt;&lt; &quot;match&quot; &lt;&lt; std::endl;
      } else {
        std::cout &lt;&lt; &quot;failed to match&quot; &lt;&lt; std::endl;
      }
    }
  }
  
  int main() {
    regex_test();
    return 0;
  }
  
  </code></pre>
  <p>On Debian Stretch, the above code prints <code>match</code> while on Mac OS BigSur it prints <code>failed to match</code>.</p>
  <p>I constructed the regex with <code>std::regex::collate</code> and set the locale in order to make the expression be locale sensitve. The expression <code>\w</code> should capture all unicode word characters. That is true on Linux, but not on Mac OS.</p>
  <p>I suspected that it might be locale related, so I changed the locale to <code>en_US.UTF-8</code> on Mac OS, but it did not work.</p>
  <p>Also I tried to change the compiler from GCC 6.3.0 to Clang 12 on Linux, and the result is still the same as GCC. On Mac OS I have not tried switching the compiler from Apple Clang to GCC.</p>
  <p>Could you please help me with this issue? Thanks!</p>