views:

878

answers:

3

I'd like to use a Regex parser to aid in some string processing in a C application. I'm ideally looking for something lightweight and open-source. The target platform is an embedded system so we're looking to save as much as possible with memory consumption in particular. I've found a number of options online but was wondering if anyone can make additional suggestions that may help in this particular context.

Many thanks,

+4  A: 

If you don't require a full featured regex implementation (and it sounds like you don't) then the code written by Brian Kernighan and Rob Pike highlighted in Beautiful Code will probably work for your needs. I found a Dr. Dobb's article which I think is the origination of the code which appears in the book.

cfeduke
+3  A: 

Scintilla, an open source text editor component, uses Ozan S. Yigit's RE engine

It was chosen because it is in the public domain (so no encumbering license) and very lightweight. But it is a bit limited... For what it is worth, RESearch.cxx uses a slightly more modern code (converted to C++ but it shouldn't be complex to convert it back to C) with some minor extensions made by myself (support of \d \s \w etc.).

There are some alternatives, like Henry Spencer's regular expression libraries.

Come to think of it, the Lua regex engine (in string library, gsub implementation among others) is probably fast and small too, like the language itself. It has its quirks and limitations, but it is very usable.

The side project LPeg can be an interesting alternative to REs, still lightweight yet powerful.

PhiLho
Thanks for the details... I think I'm going to go with RESearch.cxx for now. It does what I need and it seems to do it efficiently. Thanks!
Andrew Flanagan
A: 

Given your lightweight requirements, I'd recommend Henry Spencer's regex library which implements the POSIX BRE and ERE regex flavors. These are standard regex flavors that your users are likely already familiar with.

Jan Goyvaerts