Archive for March, 2008

Posix Regex

Wednesday, March 12th, 2008

Hi there!

I’m Redj, Ecere Contributor. :) This is my first post and I hope to be posting more and more as I have interesting news to report or cool code snippets like I have today.

Here is an early implementation of a Regex class the ecere way…

Download Regex.ec

Just add Regex.ec to your project and use it as follows:


import "Regex"

void TestRegex()
{
   char * result;
   Regex regex { "[abc][xyz]", true };
   if((result = regex.Match("match me aZ I am")))
      printf("we have a match: %s\n", result);
}

Note that at line 6, “[abc][xyz]“ sets the regex property and true sets the caseInsensitive property.

If you need the POSIX Regex extended syntax, just set the extendedSyntax property to true. Do the same for the newLineException, lineStartException and lineEndException properties if you need them. If you don’t know what they are, you probably don’t need them.

For Windows users: Note that in order to use this class, you will need to download the user contributed mingw regex library mingw-libgnurx-2.5.1-bin.tar.gz and extract it’s contents (libgnurx-0.dll) to Ecere SDK’s bin directory. You will also need this regex.h file to be present in mingw’s include directory.

For Linux users: Make sure your include paths are correctly set to find regex.h and you should be all set.

If you need assistance or would like to give use feedback, join us in #ecere on freenode.net or visit the forums and wiki (see links in the Ecere section of the sidebar).

That’s it for now. Enjoy!

Posted by Redj