Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lightweight regex parser

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,

like image 855
5 revs, 3 users 96% Avatar asked Feb 03 '23 12:02

5 revs, 3 users 96%


2 Answers

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.

like image 71
PhiLho Avatar answered Feb 06 '23 09:02

PhiLho


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.

like image 39
cfeduke Avatar answered Feb 06 '23 09:02

cfeduke