#include <cassert>
#include <string>
#include <iostream>
#include "boost/regex.hpp"
using namespace std;
using namespace boost;
void main()
{
regex reg("\\d{3}([a-zA-Z]+).(\\d{2}|N/A)\\s\\1");
string correct = "123Hello N/A Hello";
string incorrect = "123Hello 12 hello";
if(regex_match(correct,reg))
cout << correct.c_str() << " 匹配" << endl;
else
cout << correct.c_str() << " 不匹配" << endl;
if(regex_match(incorrect,reg))
cout << incorrect.c_str() << " 匹配" << endl;
else
cout << incorrect.c_str() << " 不匹配" << endl;
system("pause");
#include <string>
#include <iostream>
#include "boost/regex.hpp"
using namespace std;
using namespace boost;
void main()
{
regex reg("\\d{3}([a-zA-Z]+).(\\d{2}|N/A)\\s\\1");
string correct = "123Hello N/A Hello";
string incorrect = "123Hello 12 hello";
if(regex_match(correct,reg))
cout << correct.c_str() << " 匹配" << endl;
else
cout << correct.c_str() << " 不匹配" << endl;
if(regex_match(incorrect,reg))
cout << incorrect.c_str() << " 匹配" << endl;
else
cout << incorrect.c_str() << " 不匹配" << endl;
system("pause");
}
运行结果如下: