#include "string" #include "greta/regexpr2.h" //greta from http://research.microsoft.com/en-us/downloads/bd99f343-4ff4-4041-8293-34c054efe749/default.aspx using namespace std; using namespace regex; int main(int argc, char* argv[]) { //Match success: // result 0: $12.34 // result 1: 12 // result 2: .34 // result 3: 34 match_results results; string str("this book cost $12.34."); rpattern pat("\\$(\\d+)(\\.(\\d\\d))?", GLOBAL|NOCASE|ALLBACKREFS); match_results::backref_type br = pat.match(str, results); if( br.matched ) { printf("Match success:\n"); for (int i = 0; i < results.cbackrefs(); i++) { printf("\t result %d: %s\n", i, results.backref(i).str().c_str()); } } else { printf("Match failed.\n"); } //Subst count 1: // result: Hello, peggy! subst_results results_subst; string str1("Hello, foolbear!"); rpattern pat_subst("foolbear", "peggy", GLOBAL|NOCASE); int count_sub = pat_subst.substitute(str1, results_subst); printf("Subst count %d:\n\t result: %s\n", count_sub, str1.c_str()); //Split count 5 // split: c: // split: 1 // split: 2 // split: 3 // split: 4.txt split_results results_split; string str2("c:\\1\\2\\3\\4.txt"); rpattern pat_split("\\"); int count_sp = pat_split.split(str2, results_split); printf("Split count %d\n", count_sp); for (int i = 0; i < count_sp; i++) { printf("\t split: %s\n", results_split[i].c_str()); } return 0; }
^_^
2010年6月22日星期二
VC6 下正则库 greta 的测试
本站文章除注明外,均为本站原创
转载请注明文章转载自: 大笨熊乐园 [ https://blog.foolbear.com/?m=0 ]
文章标题: VC6 下正则库 greta 的测试
文章地址: https://blog.foolbear.com/2010/06/vc6-greta.html?m=0
转载请注明文章转载自: 大笨熊乐园 [ https://blog.foolbear.com/?m=0 ]
文章标题: VC6 下正则库 greta 的测试
文章地址: https://blog.foolbear.com/2010/06/vc6-greta.html?m=0
订阅:
博文评论
(
Atom
)
没有评论 :
发表评论