#include <iostream>
#include <string>
#include <regex>
using namespace std;
void Test(const char* str, const char* regExpression)
{
regex rx(regExpression);
bool match = regex_match(str, rx);
bool search = regex_search(str, rx);
cout << "String: " << str << " expression: " << regExpression <<
" match: " << (match ? "yes" : "no ") <<
" search: " << (search ? "yes" : "no ") << endl;
}
int main()
{
Test("a", "a");
Test("a", "abc");
return 0;
}
在 g++ 中的结果:
String: a expression: a match: yes search: no
String: a expression: abc match: no search: no
VS2012 中的结果:
String: a expression: a match: yes search: yes
String: a expression: abc match: no search: no
什么是正确的结果?另外,regex_match 和 regex_search 有什么区别?