TEST(UT_RegExp, atlrx)
{
CAtlRegExp<> reUrl;
CAtlREMatchContext<> mcUrl;
REParseError status;
const CAtlREMatchContext<>::RECHAR* szStart = 0;
const CAtlREMatchContext<>::RECHAR* szEnd = 0;
UINT nGroupIndex;
ptrdiff_t nLength;
//检测浮点数的正则表达式
status = reUrl.Parse("^{[-+]?\\d+}{\\.}?{\\d*}{[eE][-+]?\\d+}?$");
EXPECT_EQ(REPARSE_ERROR_OK, status);
EXPECT_EQ(TRUE, reUrl.Match( "123.e-3", &mcUrl));
EXPECT_EQ(TRUE, reUrl.Match( "-0.2", &mcUrl));
EXPECT_EQ(TRUE, reUrl.Match( "1.23", &mcUrl));
EXPECT_EQ(TRUE, reUrl.Match( "+1.23e-3", &mcUrl));
EXPECT_EQ(TRUE, reUrl.Match( "+1.23E+3", &mcUrl));
EXPECT_EQ(TRUE, reUrl.Match( "-1.23", &mcUrl));
//查找宏定义中的值
status = reUrl.Parse(
"^{#define\\b+}{[a-zA-Z0-9_]+\\b+}+{0x\\h+}" ); //^{#define\\b+}({\\a+_?\\a+})+{\\b+}{0x\\h}
EXPECT_EQ(REPARSE_ERROR_OK, status);
EXPECT_EQ(TRUE, reUrl.Match( "#define RE_ABC_123_DEF 0x0101", &mcUrl));
mcUrl.GetMatch(nGroupIndex=2, &szStart, &szEnd);
nLength = szEnd - szStart;
EXPECT_EQ(0, memcmp("0x0101", szStart, nLength));
}
参考:
http://www.cnblogs.com/-clq/archive/2012/03/19/2406036.html
http://www.cnblogs.com/hjslovewcl/articles/2314311.html