溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Boost之正則表達(dá)式Regex庫的使用方法

發(fā)布時間:2020-06-30 02:17:25 來源:網(wǎng)絡(luò) 閱讀:2320 作者:liam2199 欄目:編程語言

這個程序可以簡潔的挑出了目標(biāo)字符串。

#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]*)");//定義正則表達(dá)式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;  
} 
向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI