请问正则表达式怎么在VC里用?具体一点行吗?
解决方案 »
- 如何让另一个应用程序最大话
- MenuItemFromPoint的参数从何而来
- 请问在微软的DrawCli例子中是如何实现绘图过程中的橡皮线效果?
- VC程序员群
- windows2000服务程序中能否使用findwindow和postmessage如何和桌面应用程序交互
- 全局变量害死了我,怎么办?????分不够可以再加!!
- 新弹出的对话框怎么不能直接接收输入焦点?????
- 还是hook的问题,为什么我在CallWndProc能捕捉到WM_NCPAINT消息,在CallWndRetProc中却捕捉不到?在GetMsgProc中也捕捉不到。
- 跪求解决方案
- VC提取EXCEL数据问题
- ListCtrl的个性显示
- 如何在对话框中使用主窗口VIEW类中的变量?
http://www.codeproject.com/cpp/OwnRegExpressionsParser.asp
"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里,请问要做些什么样的修改能行?
把下载的文件放在工程目录下
#include <string>#include "regexpr2.h"using namespace std;using namespace regex;
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; }
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)
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.
#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:这个类
//