Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Convenient wrapper of VBScript.RegExp for VC++

0.00/5 (No votes)
29 Feb 2004 1  
Regular Expression for VC++ using VBScript.RegExp

Introduction

This is a wrapper of "VBScript.RegExp" or an example of how to use "RegExp" in VC++. I have implemented some often used methods. You can add any more as you need.

The VBScript.RegExp's performance is better than JScript.RegExp, but VBScript.RegExp did not provide 'lastIndex' property, so I selected VBScript.RegExp in VC++ and implemented 'lastIndex' by myself. I supply a convenient class RegExp, and the style is like JScript.RegExp.

When you use the regexp.h and regexp.cpp, do not forget to call CoInitializeEx or CoInitialize at the beginning of your program. Any suggestion is welcome. After you finish optimizing the code, please send a copy to me.

 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;

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here