zoukankan      html  css  js  c++  java
  • boost 正则

    参考地址:http://www.cnblogs.com/wubiyu/archive/2008/11/30/1344093.html

    常用的类
    boost::regex 正则表达式

    boost::cmatch 以char数组为容器,存储匹配返回值。
    boost::smatch 以std::string为容器,存储匹配返回值。

    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

     

  • 相关阅读:
    python之名称空间
    python之对象(实例)
    python之类
    python之类和对象
    python之面向对象的程序设计
    python之函数联系
    Python之函数第三篇
    python之列表和生成器表达式篇
    网络基本概念
    Git
  • 原文地址:https://www.cnblogs.com/wangkangluo1/p/2155784.html
Copyright © 2011-2022 走看看