C++ C++;正则表达式与PCRE表达式不工作?

C++ C++;正则表达式与PCRE表达式不工作?,c++,regex,C++,Regex,我有以下代码: include <regex> include <string> TCHAR basePath[MAX_PATH]; GetCurrentDirectory(MAX_PATH, basePath); wstring test(&basePath[0]); //convert to wstring string test2(test.begin(), test.end()); //and convert to string.

我有以下代码:

  include <regex>
  include <string>
  TCHAR basePath[MAX_PATH];
  GetCurrentDirectory(MAX_PATH, basePath);

  wstring test(&basePath[0]); //convert to wstring
  string test2(test.begin(), test.end()); //and convert to string.

  std::regex rBase("(.*my-dir)");
  std::smatch sm;
  std::regex_match(test2, sm, rBase);
我需要回去

"E:\foo\bar\baz\my-dir"
如果我运行正则表达式,比如说python或javascript,它似乎可以工作,但在C语言中不行++

我遗漏了什么或者有什么其他选择


谢谢

std::regex_match
检查整个字符串是否与regex匹配,而不仅仅是它的任何部分


使用
std::regex_search
而不是
std::regex_match
或使用与整个字符串匹配的正则表达式,例如
“(.*my dir)。*”
,并使用
sm[1].str()提取子匹配项

您似乎将PCRE正则表达式库与C++11标准附带的正则表达式库混淆了。内置的C++11正则表达式仅适用于较新的编译器。PCRE不是C++标准的一部分,所以需要单独添加PCRE库。
"E:\foo\bar\baz\my-dir"