#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 の違いは何ですか?