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;
}



程序运行结果:


= == ->

相关文章

正则替换html代码中img标签的src值在开发富文本信息在移动端...
正则表达式
AWK是一种处理文本文件的语言,是一个强大的文件分析工具。它...
正则表达式是特殊的字符序列,利用事先定义好的特定字符以及...
Python界一名小学生,热心分享编程学习。
收集整理每周优质开发者内容,包括、、等方面。每周五定期发...