• Boost正则表达式库regex常用search和match示例


    Boost正则表达式库regex常用search和match示例 - 编程语言 - 开发者第2241727个问答

    Boost正则表达式库regex常用search和match示例

     
    Boost正则表达式库regex常用search和match示例
    0 votes, 0.00 avg. rating (0% score)

     

    示例很简单,但是很有针对性,可以根据示例进行不用的修改,之后加入到各种工程中。

     

     

    #include <cstdlib>
    
    #include <stdlib.h>
    
    #include <boost/regex.hpp>
    
    #include <string>
    
    #include <iostream>
    
    using namespace std;
    
    using namespace boost;
    
    	regex subexp("e[cl][oe][mc]");
    	regex expression("^select ([a-zA-Z]*) from ([a-zA-Z]*) secom");
    
    
    int main(int argc, char* argv[])
    {
     //输入:select name from table secom
     //输出:str:select name from table
     //str:name
     //str:table
     //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()<<endl;
    	}
    	else
    	{
    		cout<<"Error Match"<<endl;
    	}
    	printf("%s
    ",in.c_str());
    	while(regex_search(in.c_str(),sub,subexp))
    	{
    		//单字搜索,将每次匹配到的结果输出
    		printf("%s
    ",sub.base());
    		printf("%s
    ",sub[0].str().c_str());
    
    		in = sub[0].second;
    	}
    	return 0 ;
    }
  • 相关阅读:
    1070 结绳
    1069 微博转发抽奖
    1068 万绿丛中一点红
    1067 试密码
    1066 图像过滤
    1065 单身狗
    CSS--文本溢出与换行
    css--滤镜filter
    css--flex布局
    css--table布局
  • 原文地址:https://www.cnblogs.com/lexus/p/3654185.html
Copyright © 2020-2023  润新知