Search code examples
cregexparsingrecommendation-engine

Recommendations for a C implementation of a regex parser


I'm thinking about implementing a regular expression parser in a C library I'm developing. Now, the question is: is there any open source code that I could use verbatim or with as few changes as possible? My expectations regarding the code are:

  • it needs to be written in C (not C++)
  • it needs to compile under gcc, mingw, M$VC
  • it mustn't depend on any third party or OS-specific headers/libraries (ie, everything needed to compile it must be readily available with a base installation of gcc, mingw, M$VC
  • it would be nice if it used Perl-compatible regex syntax (like PCRE in PHP).
  • ideally, the code should be as compact as possible

Are there any ready-made solutions that you could recommend? I was looking at PCRE for C and it looks like it has everything that's available in PHP (which rules), but the size (1.4MB DL) is a bit intimidating. Do you think it's a solid bet? Or are there other options worth considering?

[EDIT]

The library I'm developing is open source, BSD licence.


Solution

  • PCRE is pretty much the de facto standard of regex implementations (for a good reason). Don't worry about the size, it's big because regex implementations are complicated. Just use it anyway.