Click here to Skip to main content
Click here to Skip to main content

GRETA - How to use Regular Expressions in Visual C++ correctly

By , 3 Jan 2006
 

Introduction

GRETA gives you all the power of PERL 5 regular expressions in your C++ applications. This is the homepage of GRETA. Today, we will discuss neither regular expressions nor template classes in the GRETA library, because you can get familiar with them at the GRETA homepage. Here, I will explain how to add and build the GRETA library in Visual C++, step by step.

Download

Download GRETA's source code from GRETA homepage. For example: GRETA 2.6.4 for VC6, you will get 'greta-2.6.4-vc6.zip'. Or, you can download it from this site. Please do not download the *.lib file for GRETA (such as greta.lib etc.). You may find GRETA in the *.lib file from Microsoft. But greta.lib may not satisfy your needs. It may generate link errors.

Usage

GRETA library has six program files:

  • regexpr2.h
  • regexpr2.cpp
  • syntax2.h
  • syntax2.cpp
  • restack.h
  • reimpl2.h

Create a new 'Win32 Static Library' project for GRETA in your workspace:

  • Step 1: Create a blank workspace. For example, 'Test':

  • Step 2: Create the main project that will use GRETA. For example, 'Console' type 'Main':

  • Step 3: Create the GRETA project. Select 'Win32 Static Library' and make it a dependent of the Main project. After this, press the OK button, let the 'Pre-Compiled header' and 'MFC Support' remain unchecked:

  • Step 4: Copy those six program files from the GRETA zip package into the GRETA project's directory and add them to the project:

  • Step 5: Copy one of the example codes into the main() function. Change #include "regexpr2.h" to #include "..\greta\regexpr2.h". These examples are in the HTML file of the GRETA zip package. Select 'Main' project as the active project, then compile and run the project:

This is the final result that you get:

Now, we have successfully finished the project with GRETA. [Download example project].

If your project uses Unicode or your main project is DLL type, please go on with the following.

Unicode version

If your project (which uses GRETA) is of Unicode version, you must make the GRETA project to be of Unicode version. For example:

  • Step 1: Add a 'Unicode Debug' configuration for your GRETA project:

  • Step 2: In the project settings, add '_UNICODE' and 'UNICODE' macros into the C++ general preprocessor definitions of the corresponding 'Unicode Debug' configuration:

  • Step 3: Repeat step 1 and step 2 for the 'Main' project as well as for 'Release' configuration.

You will get 'Unicode Debug' and 'Unicode Release' configurations for both GRETA and your main project.

Runtime library

In many cases, when your main project is DLL type, you must make sure that GRETA uses the same runtime library as your main project, or you will get a link error.

  • Step 1: To find out which runtime library your main project uses:

  • Step 2: Select the same runtime library for GRETA project. Now, you can link successfully.

Q: Why do we need to download greta.lib and why the downloaded greta.lib generates link error?

A: This is because of "Unicode version" and "Runtime library". Because it is not known whether the downloaded greta.lib is of Unicode version, and it is also not known which runtime library the downloaded greta.lib uses, so it may generate link errors.

Regular expression tools

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

sswater shi
Software Developer (Senior)
China China
Member
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/

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralCompiled greta a static library but getting linker error when linking to multithreaded dllmembermanishru12327 Apr '09 - 23:23 
GeneralRe: Compiled greta a static library but getting linker error when linking to multithreaded dllmembersswater shi28 Apr '09 - 2:06 
GeneralRe: Compiled greta a static library but getting linker error when linking to multithreaded dllmemberbigstone199819 Aug '09 - 20:37 
Questionhelpmembersudarshan2520 Oct '08 - 4:14 
QuestionHelpmembersudarshan2515 Oct '08 - 0:47 
Hi
 
I would like to get the pattern which is matched.No to just match it.
I am new to STL.If u could suggest me some link to learn STL then i would be greatful.Also if some link to some popular regular expressions would be appriciated.Also if u can write a greta documentaion that would be great!!.. Your code is great.
 
Thanks
 

Sudarshan
AnswerRe: Helpmembersswater shi15 Oct '08 - 4:29 
QuestionHow to split string like "Text one\$$$Text two $$======"? Thanksmemberjfzsl25 Oct '07 - 22:46 
AnswerRe: How to split string like "Text one\$$$Text two $$======"? Thanksmembersswater shi26 Oct '07 - 15:04 
GeneralRe: How to split string like "Text one\$$$Text two $$======"? Thanksmemberjfzsl27 Oct '07 - 6:27 
GeneralBugs!!! [modified]memberjfzsl5 Nov '07 - 21:42 
AnswerRe: Bugs!!!memberjfzsl20 Dec '07 - 15:16 
QuestionMulti-threaded DLL (/MD)memberLin Lin27 Sep '06 - 23:34 
AnswerRe: Multi-threaded DLL (/MD)membersswater shi28 Sep '06 - 0:26 
GeneralCannot compile sample projectmembernamyrettol18 Sep '06 - 0:02 
GeneralRe: Cannot compile sample projectmembersswater shi18 Sep '06 - 4:38 
GeneralRe: Cannot compile sample projectmembermiaoux20 Sep '06 - 6:12 
GeneralRe: Cannot compile sample projectmemberpsykokwak4 Mar '07 - 3:04 
GeneralRe: Cannot compile sample projectmember123qwertz19 Mar '07 - 0:17 
GeneralRe: Cannot compile sample projectmemberEvan Lin27 Oct '08 - 21:52 
GeneralHelp!!!memberRazr33323 Aug '06 - 2:53 
GeneralRe: Help!!!membersswater shi23 Aug '06 - 14:18 
GeneralHELPmemberjeffk8328 Mar '06 - 15:29 
AnswerRe: HELPmembersswater shi28 Mar '06 - 15:46 
GeneralCAtlRegExpmemberumeca7410 Jan '06 - 8:20 
GeneralRe: CAtlRegExpmemberIgor_Solovyov_10 Jan '06 - 10:13 

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

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 3 Jan 2006
Article Copyright 2006 by sswater shi
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid