Knowledge Base Nr: 00230 RegexpSupport.cpp - http://www.swe-kaiser.de
Downloads:
MFC: Unterstützung von 'Regulär Expressions'
//es wird eine klasse 'Regexp' von www.codeguru verwendet:
// Guy Gascoigne - Piggford (ggp@bigfoot.com) Friday, February 27, 1998 using code from Henry Spencer.
#include "../cpp_classes/RegexpSupport.h"
void CMyregexp_testDlg::OnButton1()
{
BOOL bIgnoreCase = FALSE;
CRegexpSupport re("^[\t ]*([a-zA-Z.!]*)[\t ]*\\((.*)\\)", bIgnoreCase);
CString str( "doedelzipp.com!lulli (Lulli)\n" );
if (re.Match(str) && (re.SubStrings() == 2))
{
CString name, addr;
addr = re[1]; //"doedelzipp.com!lulli"
name = re[2]; //"Lulli"
TRACE("name:<%s>\naddr:<%s>\n\n", (const char*)name, (const char*)addr);
//name:<Lulli>
//addr:<doedelzipp.com!lulli>
}
}
void CMyregexp_testDlg::OnButton2()
{
BOOL bIgnoreCase = TRUE;
CRegexpSupport re1("(lulli).*(Lulli)", bIgnoreCase);
CString str( "doedelzipp.com!lulli [Lulli] hugo\n" );
if (!re1.CompiledOK())
{
TRACE("compile error:<%s>\n", (const char*)re1.GetErrorString() );
}
if (re1.Match(str))
{
CString t1;
t1 = re1.GetReplaceString("gefunden <&> treffer1:<\\1> treffer2:<\\2> ende");
TRACE("replace:<%s>\n", (const char*)t1);
//replace:<gefunden <lulli [Lulli> treffer1:<lulli> treffer2:<Lulli> ende>
}
}