C++ 调用Boost 使用正则表达式实例

#include
#include
#include  
#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");

}


运行结果如下:


你可能感兴趣的:(Boost)