1

下面的程序输出是“它不匹配”,但理想情况下应该是“它匹配”?

#include <iostream>
#include <string>
#include <regex>

using namespace std;
using namespace regex_constants;

int main()

{
    string pattern = "[a]*";
    try {
        regex re(pattern, extended);
        if(regex_match("aaaa", re))
           cout << "It is matching" << endl;
        else
           cout << "It is not matching" << endl; 
    }catch(regex_error &e)
    {
       cout << e.what() << endl;
    }
    return 0;
}
4

1 回答 1

0

尝试用 Clang 编译

clang++ -std=c++0x -stdlib=libc++ yourfile.cpp

Clang (3.3) 支持正则表达式,GCC 还不支持。

于 2013-05-09T15:30:36.877 回答