正则表达式一例

在vs2005调试通过,代码摘自网络。

#include <atlrx.h>

int main(int argc, char* argv[])
{

    //
    
//  ****************************************
    
// 
    
//  正则表达式 一例
    
// 
    CAtlRegExp<> reUrl;
    // Five match groups: scheme, authority, path, query, fragment
    REParseError status = reUrl.Parse(
        "({[^:/?#]+}:)?(//{[^/?#]*})?{[^?#]*}(?{[^#]*})?(#{.*})?" );

    if (REPARSE_ERROR_OK != status)
    {
        // Unexpected error.
        return 0;
    }

    CAtlREMatchContext<> mcUrl;
    if (!reUrl.Match(
        "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_s("%d: "%.*s" ", nGroupIndex, nLength, szStart);
    }
    //
    
//  ***************************************
    
//

    return 0;

} 

原文地址:https://www.cnblogs.com/ant-wjf/p/3154878.html