ATLVisual C++ 7.1Visual Studio 6Visual C++ 7.0Windows 2003Windows 2000Visual C++ 6.0Windows XPMFC中级开发Visual StudioWindowsC++
VC++ 的 VBScript.RegExp 方便封装






4.50/5 (7投票s)
使用 VBScript.RegExp 实现的 VC++ 正则表达式
引言
这是一个 "VBScript.RegExp
" 的封装,或者说是在 VC++ 中使用 "RegExp" 的一个例子。我已经实现了一些常用的方法,您可以根据需要添加更多方法。
VBScript.RegExp
的性能优于 JScript.RegExp
,但 VBScript.RegExp
没有提供 'lastIndex
' 属性,所以我选择在 VC++ 中使用 VBScript.RegExp
并自己实现了 'lastIndex
'。我提供了一个方便的类 RegExp
,其风格类似于 JScript.RegExp
。
在使用 regexp.h 和 regexp.cpp 时,请不要忘记在程序的开头调用 CoInitializeEx
或 CoInitialize
。 欢迎提出任何建议。 在您完成代码优化后,请将副本发送给我。
CoInitializeEx( NULL, COINIT_MULTITHREADED );
RegExp re;
re.IgnoreCase( TRUE );
re.compile( _T("\w([\d.]*)(\w+)") );
re.exec( _T("I f3454ind it, f567.56ind it again") );
cout << re.index << _T(" ~ ") << re.lastIndex << endl;
cout << (LPCTSTR)re.SubMatch( 0 ) << endl;
cout << (LPCTSTR)re.SubMatch( 1 ) << endl << endl;