#include <regex>
#include <string>
#include <iostream>
using namespace std;
void regex_test()
{
string pattern("[^c]ei");
pattern = "[[:alpha:]]*" + pattern + "[[:alpha:]]*";
regex r(pattern,regex::icase);
smatch results;
string test_str("receipt frEind theif receive");
if (regex_search(test_str, results, r)){
cout << results.str(0) << endl;
cout << "before "<<results.prefix().str() << endl;
cout << "after "<<results.suffix().str() << endl;
}
if (regex_match(test_str, r)){
cout << "ture" << endl;
}
else{
cout << "false" << endl;
}
for (sregex_iterator ite(test_str.begin(), test_str.end(), r), end_ite; ite != end_ite; ++ite){
cout << ite->str()<< endl;
}
pattern = "(\\()?(\\d{3})(\\))?([-. ])?(\\d{7})";
regex re_tell(pattern);
string tell_str("123-1234567");
if (regex_match(tell_str, re_tell)){
cout << "phone matched" << endl;
}
else{
cout << "phone did not match" << endl;
}
}