int main(int argc, char* argv[])
{
CAtlRegExp<> reUrl; // five match groups: scheme, authority, path, query, fragment
REParseError status = reUrl.Parse(
_T("({[^:/?#]+}:)?(//{[^/?#]*})?{[^?#]*}(?{[^#]*})?(#{.*})?" ));
if (REPARSE_ERROR_OK != status)
{
// Unexpected error.
return 0;
} CAtlREMatchContext<> mcUrl;
if (!reUrl.Match( _T("http://search.microsoft.com/us/Search.asp?qu=atl&boolean=ALL#results"),
&mcUrl))
{
// Unexpected error.
return 0;
} for (UINT nGroupIndex = 0; nGroupIndex < mcUrl.m_uNumGroups;
++nGroupIndex)
{
const CAtlREMatchContext<>::RECHAR* szStart = 0;
const CAtlREMatchContext<>::RECHAR* szEnd = 0;
mcUrl.GetMatch(nGroupIndex, &szStart, &szEnd); ptrdiff_t nLength = szEnd - szStart;
printf("%d: \"%.*s\"\n", nGroupIndex, nLength, szStart);
}
system("pause");
}这是MSDN上关于CAtlRegExp正则表达式类的示例代码,按道理输出应该如下
0: "http"
1: "search.microsoft.com"
2: "/us/Search.asp"
3: "qu=atl&boolean=ALL"
4: "results"但是现在的结果是
0: "h"
1: "s"
2: "/"
3: "q"
4: "r"
我唯一更改了代码的地方就是在正则表达式和url那两个字符串上加了_T()宏
怎么这么奇怪啊 我用的编译器是VS2008