PCRE正则库婚配Unicode中文

PCRE正则库匹配Unicode中文
本帖最后由 yjip267 于 2014-06-23 10:03:53 编辑
求PCRE正则库匹配Unicode中文的正则表达式。[\\x{4e00}-\\x{9fa5},匹配不到吗?是不是这个表达式在RCRE的写法不正确呢?在ASCII下面\\x80-\\xff;就能匹配到中文。用的是VC里面调用RCRE库。Unicode字符串怎么匹配。如我想匹配一个http。怎么写\\x[http]不对。
------解决方案--------------------
我也网上找到的。可以用
#include <..\pcre\include\pcre.h>  
  
int _tmain(int argc, _TCHAR* argv[])  
{  
    std::wstring sSrcReal = L"ahsf(agsh艾丝凡);asghjgah(ahsjhj);(&*(^&&*AS%Q(asg1asg); ajshfghasfg";  
    std::string sSrcRealUtf_8 = CW2A(sSrcReal.c_str(), CP_UTF8);  
  
     
    // 使用PCRE提取用户ID  
    std::string sRulesUtf_8 = CW2A(L"(?<=\\()[\\w\u4E00-\u9FFF]+(?=\\);)", CP_UTF8);  
  
    int nOptions = PCRE_EXTENDED 
------解决方案--------------------
 PCRE_UTF8;  
    const char *pError;  
    int nErroffset;  
  
    // 构造pcre结构  
    pcre *pRe = pcre_compile(  
        sRulesUtf_8.c_str(),  
        nOptions,  
        &pError,               /* for error message */  
        &nErroffset,           /* for error offset */  
        NULL);                /* use default character tables */  
  
    std::vector<std::wstring> sPcreOut;  
    int nPos = 0;  
    int nRet = 1;  
    while(pRe && nRet > 0)  
    {  
        int ovector[30];   // 必须为3的整数倍  
          memset(&ovector, -1, sizeof(ovector));  
       
        // 执行正则表达式匹配  
        nRet = pcre_exec(  
            pRe,                   /* the compiled pattern */  
            NULL,                 /* no extra data - we didn't study the pattern */  
            sSrcRealUtf_8.c_str(),//subject,              /* the subject string */  
            (int)sSrcRealUtf_8.size(),       /* the length of the subject */  
            nPos,                    /* start at offset 0 in the subject */  
            0,                    /* default options */  
            ovector,              /* output vector for substring information */  
            sizeof(ovector) / sizeof(ovector[0]));           /* number of elements in the output vector */  
  
        // ovector[0]存储匹配的首字符位置,ovector[1]存储匹配字符串后的第一个不匹配的字符位置  
        if(nRet > 0)  
        {  
            nPos = ovector[1];  
            std::string sSub = sSrcRealUtf_8.substr(ovector[0], nPos - ovector[0]);  
            std::wstring sTemp = CA2W(sSub.c_str(), CP_UTF8);  
            sPcreOut.push_back(sTemp);