I have the code below this:
#include <string>
#include <regex>
int main(int argc, char const *argv[]) {
std::string s = "_apple_";
std::regex r1("_(\\s|\\S)+_");
std::regex r2("_[\\s\\S]+_");
std::regex r3("_.+_");
std::regex r4("_[pale]+_");
std::smatch sm;
printf("r1:%d r2:%d r3:%d r4:%d\n",
std::regex_match(s, sm, r1),
std::regex_match(s, sm, r2),
std::regex_match(s, sm, r3),
std::regex_match(s, sm, r4));
return 0;
}
output:r1:1 r2:0 r3:1 r4:1
I can not understand why r2 is not match?
My environment is:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 10.0.0 (clang-1000.11.45.5) Target: x86_64-apple-darwin17.7.0 Thread model: posix InstalledDir:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin.