Greta 入门指南
来源:互联网 发布:生化危机剧情 知乎 编辑:程序博客网 时间:2024/06/08 19:09
GRETA是微软研究院推出的一个正则表达式模板类库,GRETA 包含的 C++ 对象和函数,使字符串的模式匹配和替换变得很容易,它们是:
rpattern: 搜索的模式
match_results/subst_results: 放置匹配、替换结果的容器
为了执行搜索和替换的操作,用户首先需要用一个描述匹配规则的字符串来显式初始化一个rpattern对象,然后把需要匹配的字符串作为参数,调用rpattern的函数,比如match()或者substitute(),就可以得到匹配后的结果。如果match()/substitute()调用失败,函数返回false,如果调用成功,函数返回true,此时,match_results对象存储了匹配结果。请看例子代码:
#include <iostream>#include <string>#include "regexpr2.h"#ifdef _UNICODE#define tstring wstring#define tcout wcout#else#define tstring string#define tcout cout#endifusing namespace std;using namespace regex;int main() { match_results results; tstring str( _T("The book cost $12.34") ); rpattern pat( _T("\\$(\\d+)(\\.(\\d\\d))?") ); // Match a dollar sign followed by one or more digits, // optionally followed by a period and two more digits. // The double-escapes are necessary to satisfy the compiler. match_results::backref_type br = pat.match( str, results ); if( br.matched ) { tcout << ("match success!") << endl; tcout << ("price: ") << br << endl; } else { tcout << ("match failed!") << endl; } return 0;}
程序输出结果:
match success!price: $12.34
0 0
- Greta 入门指南
- GRETA
- GRETA 用法
- greta使用
- 入门指南
- 入门指南
- 入门指南
- 入门指南
- GRETA: The GRETA Regular Expression Template Archive
- greta类初探
- GRETA--亲亲大麦壳
- GRETA 正则表达式库
- GRETA 正则表达式库
- GRETA 正则表达式库
- 顺利编译GRETA
- greta 编译,配置,使用
- Using GRETA in VS2008
- Greta 编译错误
- springMVC每一层的注解
- 短信接口被攻击后的处理
- 自定义Dialog
- 341. Flatten Nested List Iterator【M】【42】
- 【题】【差分约束】NKOJ 2457 矩阵问题
- Greta 入门指南
- 一个都不能少观后感
- springMVC事务和仓库注解
- Android StackView用法
- 回溯法——combination-sum、combination-sum-ii
- JVM性能调优2:JVM性能调优参数整理
- :Hadoop、NoSQL、分布式、lucene、solr、nutch kafka入门:简介、使用场景、设计原理、主要配置及集群搭
- js根据数组对象中某属性进行排序
- Linux挂载移动硬盘