boost 正则
參考地址:http://www.cnblogs.com/wubiyu/archive/2008/11/30/1344093.html
常用的類(lèi)
boost::regex 正則表達(dá)式
boost::cmatch 以char數(shù)組為容器,存儲(chǔ)匹配返回值。
boost::smatch 以std::string為容器,存儲(chǔ)匹配返回值。
boost::regex_match 匹配算法
boost::regex_search 查找算法
boost::regex_replace 替換算法
* =====================================================================================
*
* Filename: reg2.cc
*
* Description:
*
* Version: 1.0
* Created: 08/27/2011 09:21:07 PM
* Revision: none
* Compiler: gcc
*
* Author: kangle.wang (mn), wangkangluo1@gmail.com
* Company: APE-TECH
*
* =====================================================================================
*/
#include <cstdlib>
#include <stdlib.h>
#include <boost/regex.hpp>
#include <string>
#include <iostream>
usingnamespace std;
usingnamespace boost;
regex expression("^select ([a-zA-Z]*) from ([a-zA-Z]*)");
int main(int argc, char* argv[])
{
std::stringin;
cmatch what;
cout <<"enter test string"<< endl;
getline(cin,in);
if(regex_match(in.c_str(), what, expression))
{
for(int i=0;i<what.size();i++)
cout<<"str :"<<what[i].str()<<endl;
}
else
{
cout<<"Error Input"<<endl;
}
return0;
}
編譯:
g++ -g -Wall -O0 reg2.cc -o reg2 -lboost_regex
?
output*******
enter test string
select name from table
str :select name from table
完
總結(jié)
- 上一篇: 人也女马白勺
- 下一篇: 《暗时间》的笔记-我在南大的七年