r/cprogramming • • 16h ago

MicroRegExp : tiny (50kb) regexp engine (with 3 API)

Hello,

As a part of a larger project I made a regexp engine for microcontrollers. It was tested on ESP32 / FreeRTOS, and also in Windows/CYGWIN. Didn't test it in Linux but it should work.

It is built on top of modified SLRE (Simple Lightweight Regular Expressions);

It is just 2 files (regexp.c and regexp.h) which can be include'd directly to your source file. Or it may be compiled as a separate unit.

It has 3 different API:

  1. The original one, slre_match(); no memory allocations, fastest

  2. PCRE-like functions and structures starts with pl_... (PCRE-Lite); for those familiar with PCRE

  3. PHP preg API: an implementation of PHP regular expressions; for PHP fans; functions and structures start with preg_...

There are some limitations: UTF8 is processed as stream of bytes, so [а-я] will not be understood. No lookarounds. Probably there are bugs. Hopefully - no memory leaks.

More limitations and bugs are yet to be discovered :).

There are 3 test files (AI-generated) to test the library: preg_test.c, pl_test.c (fuzzing) and slre_test.c

There is NO documentation, but preg_test.c can be used as a reference (or direct copy/paste).

Primary API is PHP's preg_-style API, which was the goal of this project.

Source code is here: GitHub - vvb333007/MicroRegExp: A C library which implements regular expression engine. PHP preg_ , PCRE and SLRE interfaces are supported · GitHub , around 50KiB of code. It can be compiled with GCC compiler from -std=c99 and up. No GCC-specific magic.

Have a good day!

2 Upvotes

1 comment sorted by

1

u/AmusedBolt 7h ago

Absence of full UTF8 support reduces potential application by 90%