zoukankan      html  css  js  c++  java
  • DEELX 正则引擎编程示例:连续查找

      

     为了尽快的掌握DEELX中正则表达是的 应用,下面写了一个小程序(我一直相信,带着问题去学习总会更大程度的激发我们的能动性,加深我们对知识的理解)。

    下面这个实例程序主要用于匹配一串代码中的("|"   "->"  "="  "=="  "+" "-" )串,其中应当注意的是“==”和“=”,应该把"=="正则表达式优先获得匹配.

    不多解释了,上代码.

    #include <iostream>
    #include "deelx.h"
    using namespace std;
    
    int main()
    {
        string rex="(==)|((?[^=!+-*])=)|(->)|-|+|(\\|)";
        string math="int a=12; if (a==b) return p->x;";
        static CRegexpT <char> regexp(rex.c_str());
        CContext * pContext = regexp.PrepareMatch(math.c_str());
        MatchResult result=regexp.Match(pContext);
        while(result.IsMatched())
        {
            int start=result.GetStart();
            int end=result.GetEnd();
            cout<<math.substr(start,end-start)<<endl;
            result=regexp.Match(pContext);
    
        }
       regexp.ReleaseContext(pContext);
        return 0;
    }
    



    程序运行结果:


    =
    ==
    ->

  • 相关阅读:
    bzoj1009
    bzoj1576 3694
    bzoj3143
    bzoj1391
    bzoj2729
    bzoj2653
    bzoj3261
    bzoj2326
    人件
    优秀的产品
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3063612.html
Copyright © 2011-2022 走看看