请问正则表达式怎么在VC里用?具体一点行吗?

解决方案 »

  1.   

    http://www.codeproject.com/cpp/rexsearch.asp
    http://www.codeproject.com/cpp/OwnRegExpressionsParser.asp
      

  2.   

    C++目前不支持正则表达式,但是网上有很多开源的库,比如boost,
      

  3.   

    开源库我要源码现在没用我要的是在MFC下能用的正则表达式
      

  4.   

    http://www.fruitfruit.com/vc/boost/boost_regex_test.cpp
      

  5.   

    MFC没有,VC没有,只有第三方的库,比如boost,有源码也有库
      

  6.   

    #include <iostream>#include <string>#include "regexpr2.h"using namespace std;using namespace regex;#pragma comment(lib, "greta")int main() {    match_results results;    string str(//"http://search.microsoft.com/us/Search.asp?qu=atl&boolean=ALL#results"
    "The book cost $12.34" 
    );    rpattern pat( //"({[^:/?#]+}:)?(//{[^/?#]*})?{[^?#]*}(?{[^#]*})?(#{.*})?"
    "\\$(\\d+)(\\.(\\d\\d))?" 
    );      // Match a dollar sign followed by one or more digits,    // optionally followed by a period and two more digits.    // The double-escapes are necessary to satisfy the compiler.     match_results::backref_type br = pat.match( str, results );    if( br.matched ) {        cout << "match success!" << endl;        cout << "price: " << br << endl;    } else {        cout << "match failed!" << endl;    }    return 0;}这样是可以的,可是我想放在MFC里,请问要做些什么样的修改能行?
      

  7.   

    #include <iostream>
    把下载的文件放在工程目录下
    #include <string>#include "regexpr2.h"using namespace std;using namespace regex;
      

  8.   

    在InitDialog中加入
    match_results results; string str(//"http://search.microsoft.com/us/Search.asp?qu=atl&boolean=ALL#results"
    "The book cost $12.34" 
    ); rpattern pat( //"({[^:/?#]+}:)?(//{[^/?#]*})?{[^?#]*}(?{[^#]*})?(#{.*})?"
    "\\$(\\d+)(\\.(\\d\\d))?" 
    );   // Match a dollar sign followed by one or more digits, // optionally followed by a period and two more digits. // The double-escapes are necessary to satisfy the compiler. match_results::backref_type br = pat.match( str, results ); if( br.matched ) { cout << "match success!" << endl; cout << "price: " << br << endl; } else { cout << "match failed!" << endl; }
      

  9.   

    编译通过,注意下载的是针对vc6的还是针对vc7的
      

  10.   

    我按你的方法出错:
    Linking...
    msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (??1?$basic_strin
    g@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in greta.lib(regexpr2.obj)
    msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(char const *,class basic_
    string<char,struct std::char_traits<char>,class std::allocator<char> >::allocator<char> const &)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBDABV?$allocator@D@1@@Z) already defined in greta.lib(regexpr2.obj)
    LINK : warning LNK4098: defaultlib "LIBC" conflicts with use of other libs; use /NODEFAULTLIB:library
    Debug/MyR.exe : fatal error LNK1169: one or more multiply defined symbols found
    Error executing link.exe.MyR.exe - 3 error(s), 1 warning(s)
      

  11.   

    针对error LNK2005链接错误的解决方法:
    RESOLUTION
    There are two ways to resolve this problem. The first solution involves forcing the linker to link the libraries in the correct order. The second solution allows you to find the module that's causing the problem and correct it. Solution One - Force Linker to Link Libraries in Correct OrderOpen the Project Settings dialog box by clicking Settings on the Build menu. in the Settings For view, select (highlight) the project configuration that's getting the link errors. Click the Link tab. Select INPUT in the Category combo box. In the Libraries to Ignore edit box, insert the library names (for example, Nafxcwd.lib Libcmtd.lib) 
    NOTE: The linker command line equivalent in /NOD:<library name> 
    In the Object/library Modules edit box, insert the library names. You must ensure that these are listed in order and as the first two libraries in the line (for example, Nafxcwd.lib Libcmtd.lib). Solution Two - Find the Problem Module and Correct It
    Perform the following steps to see the current library link order: 
    Open the Project Settings dialog box by clicking Settings on the Build menu. In the Settings For view, Select (highlight) the project configuration that's getting the link errors . Click the Link tab. Type the following in the Project Options dialog box: 
    /verbose:lib 
    Rebuild your project. The libraries will now be listed in the output window during the linking process.
      

  12.   

    The following program uses a regular expression to extract parts of a URL.#include "stdafx.h"
    #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("%d: \"%.*s\"\n", nGroupIndex, nLength, szStart);
       }}
    Output
    0: "http"
    1: "search.microsoft.com"
    2: "/us/Search.asp"
    3: "qu=atl&boolean=ALL"
    4: "results"
    Requirements
    Header: atlrx.hMSDN,vs2003 ATL Server 中有 正则表达式类,MFC 中添加ATL 支持后 可以用,很简单,够用了。////
    CAtlRegExp:这个类
    //
      

  13.   

    MFC中怎么样添加ATL支持????