greta的基本使用已经掌握,但是我想知道他的复杂使用
网络只给出了一个简单的例子,我想知道他其他具体函数的使用方式简单的程序
CString a = "<meta http-equiv=\"refresh\" content=\"0;url=index.asp\">";
string str=a.GetBuffer(0);
match_results results;
rpattern pat("url[:=](\/)?([^>#\" ]*)");
match_results::backref_type br = pat.match( str.c_str(), results );
if( br.matched ) 
{
        cout << "match success!" << endl;
        cout << "price: " << br << endl;
} else 
{
        cout << "match failed!" << endl;
}
自己看了半天终于得到了好的结果,但是仍旧有个疑问CString a = "The book cost $12.34 baioodu.hehe";
string str=a.GetBuffer(0);
match_results results;rpattern pat("(oo)",NOCASE | GLOBAL | ALLBACKREFS );
int icount = pat.count(str.c_str());
match_results::backref_type br = pat.match( str.c_str(), results);
match_results::backref_vector c = results.all_backrefs();
int jj=c.size();
if( br.matched ) 
{
for(int i=0;i<icount*pat.cgroups();i++)
{
printf("%d-%s\n",i,c[i]);
}} 
else
{
        cout << "match failed!" << endl;
}输出如下:
0-ook cost $12.34 baioodu.hehe
1-ook cost $12.34 baioodu.hehe
2-oodu.hehe
3-oodu.hehe按照我的思路应该 输出如下:
0-oo
1-oo
就可以了。。可是得到了上面的结果。。继续等待回答

解决方案 »

  1.   

    下面代码在VS 2003上调试成功string str("The book cost $12.34 baioodu.hehe");
    match_results results;
    rpattern pat("(oo)", GLOBAL | ALLBACKREFS );
    int igroups = pat.cgroups();
    match_results::backref_type br = pat.match( str.c_str(), results);
    if( br.matched ) 
    {
        for(int i=0;i<results.cbackrefs();i++)
        {
            if(i%igroups == 0)
            {
                printf("%d-%s\n",i,results.backref(i).str().c_str());
            }
        }

    else
    {
        cout << "match failed!" << endl;
    }