帮忙写个正则表达式 ,很简单
NO,Name,Sex,Birthday,Chinese,Math,English,Physics,Chemistry
以NO开头,并且一定要有NO
Name,Sex,Birthday,Chinese,Math,English,Physics,Chemistry 中选择,可以是全部,也可以是没有一个,有某个属性的话一定要有“,”
[解决办法]
- C/C++ code
"NO(,((Name)|(Sex)|(Birthday)|(Chinese)|(Math)|(English)|(Physics)|(Chemistry)))*"
[解决办法]
- C/C++ code
// RegExpr.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <iostream>#include <string>#include "regexpr2.h"using namespace std;using namespace regex;int _tmain(int argc, _TCHAR* argv[]){ match_results results; string strs[] = { "NO,Name,Sex,Birthday,Chinese,Math,English,Physics,Chemistry ", "adsfasdf NO, Sex,Birthday,Chinese,Math,English", "Hello,World", " ", "123 NOhysics,Chemistry ", "NO,Chinese,Math,English,Physics,Chemistry", "NO,chinese,MATH,EnglISH,physics,CHEMISTRY", }; rpattern pat("NO(,(Name|Sex|Birthday|Chinese|Math|English|Physics|Chemistry))*", NOCASE); for (int i = 0; i < sizeof(strs)/sizeof(strs[0]); ++i) { match_results::backref_type br = pat.match( strs[i], results ); if( br.matched ) { cout <<i<<" match success : " <<br<< endl; } else { cout <<i<<" match failed!"<< endl; } } return 0;}