Click here to Skip to main content
15,886,518 members
Articles / Desktop Programming / ATL
Article

Convenient wrapper of VBScript.RegExp for VC++

Rate me:
Please Sign up or sign in to vote.
4.50/5 (7 votes)
29 Feb 2004CPOL 50.6K   656   21   9
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.

C++
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
China China
Begin coding from basic, since 1994. Interested in coding and database and website constructing.
My website: http://www.regexlab.com/ - Regular Expression Laboratory
The easiest regex engine: http://www.regexlab.com/deelx/

Comments and Discussions

 
QuestionCan I use the object from STA? Pin
AndreBroz3-Apr-12 4:50
AndreBroz3-Apr-12 4:50 
AnswerRe: Can I use the object from STA? Pin
sswater shi3-Apr-12 16:45
sswater shi3-Apr-12 16:45 
GeneralWorks Well Pin
timbolicus_prime7-Aug-08 7:15
timbolicus_prime7-Aug-08 7:15 
GeneralRe: Works Well Pin
sswater shi7-Aug-08 12:24
sswater shi7-Aug-08 12:24 
QuestionCoInitializeEx Pin
James Duy Trinh (VietDoor)8-Sep-05 17:54
James Duy Trinh (VietDoor)8-Sep-05 17:54 
AnswerRe: CoInitializeEx Pin
sswater shi8-Sep-05 18:42
sswater shi8-Sep-05 18:42 
Generalbad zip file Pin
Xiong Shijie17-Jun-04 6:23
Xiong Shijie17-Jun-04 6:23 
GeneralRe: bad zip file Pin
sswater shi17-Jun-04 15:01
sswater shi17-Jun-04 15:01 
GeneralRe: bad zip file Pin
Xiong Shijie2-Jul-04 0:23
Xiong Shijie2-Jul-04 0:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.