首页 > 其他 > 详细

Boost之正则表达式Regex库的使用方法

时间:2018-04-27 16:40:02      阅读:182      评论:0      收藏:0      [点我收藏+]
这个程序可以简洁的挑出了目标字符串。

#include <cstdlib>   
#include <stdlib.h>   
#include <boost/regex.hpp>   
#include <stdlib.h>
#include <string>   
#include <iostream>   
using namespace std;  
using namespace boost;  

regex expression("^select ([a-zA-Z]*) from ([a-zA-Z]*)");//定义正则表达式expression   

int main(int argc, char* argv[])  
{  
    std::string in;  
    cmatch what;  
    cout << "enter test string" << endl;  
    getline(cin,in);  
    if(regex_match(in.c_str(), what, expression))//regex_match:匹配算法,用于测试一个字符串是否和正则式匹配   
    {  
        for(int i=0;i<what.size();i++)  
            cout<<"str :"<<what[i].str()<<endl;  
    }  
    else  
    {  
        cout<<"Error Input"<<endl;  
    }  

    system("pause");

    return 0;  
} 

Boost之正则表达式Regex库的使用方法

原文:http://blog.51cto.com/liam2199/2108548

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!