#include <string>
#include "regexpr2.h"
using namespace std;
using namespace regex;//greta库的命名空间
//若链接出错,设置mfc静态链接
//查找匹配串
//返回结果匹配串(cstringarray数组指针类型)
cstringarray* find(lpctstr m_reg,lpctstr m_source,regex_flags dwstyle = nocase | multiline)
{
cstringarray* strarray = new cstringarray();
regex_flags dw = global | allbackrefs | dwstyle;
rpattern reg(m_reg, dw);
match_results results;
match_results::backref_type bt = reg.match(m_source, results);
int igroups = reg.cgroups();
int ncount = 0;
if(bt.matched)
for(int i=0; i<results.cbackrefs(); i++)
if(i%igroups == 0)
ncount++;
strarray->add(results.backref(i).str().c_str());
}
return strarray;
cstringarray* find2(lpctstr m_reg,lpctstr m_source,regex_flags dwstyle = nocase | multiline)
match_results::backref_vector vec = results.all_backrefs();
match_results::backref_vector::iterator iter;
for(iter = vec.begin(); iter != vec.end(); iter++)
string str = (*iter).str();
strarray->add(str.c_str());
//使用实例
cstringarray* str = find(m_reg, m_source);
for(int i=0; i< str->getsize(); i++)
afxmessagebox((*str)[i]);
//替换匹配串
//返回结果替换后字符串(cstring类型)
cstring sub(lpctstr m_reg,lpctstr m_sub, lpctstr m_source,regex_flags dwstyle = nocase | multiline)
cstring lpsub;
rpattern reg(m_reg, m_sub, dw);
subst_results results;
string str(m_source);
int ncount = reg.substitute(str, results);
lpsub = str.c_str();
return lpsub;
cstring str = sub(m_reg, m_sub, m_source);
afxmessagebox(str);
//分割串
//返回结果分割后子串(cstringarray数组类型)
cstringarray* split(lpctstr m_reg, lpctstr m_source,regex_flags dwstyle = nocase | multiline)
split_results results;
int ncount = reg.split(str, results);
for(int i=0; i<ncount; i++)
string split = results[i];
strarray->add(split.c_str());
cstringarray* str = split(m_reg, m_source);
for(int i=0; i<str->getsize(); i++)