//std::string in; cmatch what; string in="select name from table secom" ; cmatch sub ; if(regex_match(in.c_str(),what,expression)) { //regex_match : 是对整个输入块的匹配,整个块如不匹配则不能成功 for(unsigned int i=0;i<what.size();i++) cout<<"str :"<<what[i].str()<...
typedef match_results<const char*> cmatch;typedef match_results<std::string::const_iterator> smatch;typedef match_results<const wchar_t*> wcmatch;typedef match_results<std::wstring::const_iterator> wsmatch; 可以把match_results看成是一个sub_match的容器,同时它还提供了format方法来代替regex_format函数。
4 boost::regex pat2("(\\d{4}-){3}\\d{4}ok", boost::regex::icase); 5 cout << boost::regex_match(card_str2.begin()+3, card_str2.end()-3, pat2) << endl; 6 cout << boost::regex_match(card_str2.begin()+3, card_str2.end()-3, boost::regex("(\\d{4}-){3}\...
boost::regex reg2( szReg, boost::regex::extended ); 下面这个代码不仅验证是否匹配,而且可以从中提取出正则表达式括号对应的子串。 { //提取子串 boost::cmatch mat; boost::regex reg( szStr ); bool r=boost::regex_match( szStr, mat, reg); if(r) //如果匹配成功 { //显示所有子串 for(boo...
basic_regex生成和处理一个正则表达式,这个类的用法很简单,俱体用法参考文献[2]。 1.2 sub_match类 这个类处理一个子表达式的匹配结果,定义如下: template <class BidirectionalIterator> class sub_match : public std::pair<BidirectionalIterator, BidirectionalIterator> ...
std::string in; cmatch what; cout <<"enter test string"<< endl;getline(cin,in);if(regex_match(in.c_str(), what, expression))//regex_match:匹配算法,用于测试一个字符串是否和正则式匹配{for(inti=0;i<what.size();i++) cout<<"str :"<<what[i].str()<<endl; ...
(2)match_results match_results是用来表示所有匹配指定正则表达式的字符串的集合的对象类型。Boost.Regex提供了四种标准类型的定义:C单字节字符 类型的cmatch, C宽字符类型的wcmatch, C++单字节字符类型smatch, C++宽字符类型wsmatch。match_results所提供的接口参见:http://www.boost.org/doc/libs/1_37_0/libs/r...
Regex对于正则表达式提供高效有力的支持,它遵循与标准模板库(STL)相同的设计理念,这使得它的用法相当...
1. regex_match regex reg("\\d{3}");string str = "123";bool b = regex_match(str,reg);2.regex_replace(string s, regex e, string t),把s中匹配了e的子串替换为t regex reg("(colo)(u)(r)",boost::regex::icase|boost::regex::perl);string s="Colour,colour,color,...
assert(boost::regex_match(correct,reg)==true); assert(boost::regex_match(incorrect,reg)==false); } 第一个字符串,123Hello N/A Hello, 是正确的;123是3个数字,Hello是一个后跟任意字符(一个空格)的单词, 然后是N/A和另一个空格,最后重复单词Hello。第二个字符串是不正确的,因为单词Hello没有被严...