tags:

views:

156

answers:

5

Possible Duplicate:
Lightweight and portable regex library for C/C++?

I'm looking for a C++ (C is acceptable, too) library for matching regular expressions. The library should satisfy these requirements:

  • Can be built on Windows (MSVC 7 and newer)
  • Can be built on Linux (g++ 3.4 and newer).
  • Has no external dependencies; nothing but C/C++ runtime and STL allowed
  • Works reasonably fast for small (~200 characters) strings to match against

I don't need a particular regexp flavor (POSIX, PCRE etc.) so anything is fine.

So far, I considered these libraries:

  • re2: Interesting, but apparently no support for Windows builds
  • PCRE doesn't seem terribly 'small' (over 1MB zipped sources) and doesn't seem to support Windows in its buildsystem.
  • Boost Regex might fit the bill but I didn't spend much time on trying to figure out if I can build it standalone

Anything else maybe?

+1  A: 

Boost.Regex would fit your bill in terms of compilers, though it has dependencies on other parts of Boost.

Dirk Eddelbuettel
The dependencies are exactly what drives me away from Boost.Regex (as well as Boost.xpressive). :-/
Frerich Raabe
+1  A: 

A quick Google for "pcre windows" seems to say that it does, in fact, support Windows. The .so file on my system is < 200 KiB, so it doesn't seem to take up that much disk space either...

Thanatos
I'm sure that it can be built on Windows somehow, but it seems I have to write the build system for it by myself. I'm looking for something with little to no *build time* dependencies as well.
Frerich Raabe
Looking at the source code, it seems to use CMake, which can build on Windows. Does the build process fail at some point? All it should take is a simple `cmake ...; make` by the looks of it.
Thanatos
I went ahead and confirmed this: PCRE will build on Windows, and it's easy to do... `cmake path-to-pcre-source` followed by `nmake`. It builds Debug by default, but that's just an extra arg / an edit to the settings, which takes five minutes.
Thanatos
I'd +1 up you even more if I could for actually confirming your suspicion. :-} Good to know that it's not *that* hard to do. Now, maybe I should start using cmake for the rest of my codebase as well (I'm still working with handwritten Makefiles so far) so that the cmake build-time dependency of PCRE doesn't matter anymore...
Frerich Raabe
Accepting this; I ended up using PCRE. :-)
Frerich Raabe
+1  A: 

Mine! But you have to download it as part of another tool - csvfix. The regex code is in the alib library, is based on the code in Software Tools In Pascal, ported with a lot of changes to C++. It is very small, about 30K or less of source, supports ed-style rexexes, compiles on Windows and Linux, and I would love to get others to improve it.

anon
Out of curiousity: why did somebody (you?) port it to C++ instead of using another library? Or has it been so long again that there simply was no other library at that point?
Frerich Raabe
@Frerich It is quite old code, and I don't like my FOSS projects being dependent on other projects if possible. But if you need real high-power regexes, you should obviously use something like boost - my csvfix project simply doesn't need that power.
anon
@Frerich BTW, as someone who's name is always being misspelled, can I say that **French Raabe** which is how my failing eyes have always read it seems too me much cooler than your actual name :-)
anon
@Neil: Hah! It does have a certain coolness to it, that's true. Maybe I should consider it as a nickname from now on. ;-)
Frerich Raabe
+1  A: 

Try the GNU regex library.

http://www.gnu.org/s/libc/manual/html_node/Regular-Expressions.html

There's been at least one windows port:

http://people.delphiforums.com/gjc/gnu_regex.html

no
Thanks for pointing this out! Will give it a look.
Frerich Raabe
I've used this library in a little program i developed on linux and cross-compiled for windows. The windows build used this library in the form of a dll (regex2.dll) ... I found the dll laying around the internet somewhere (probably gnuwin32.sourceforge.net); someone else had built it but it worked lika a champ.
no
+2  A: 

The C++ TR1 standard libraries contain regular expression classes. Newer versions of MSVC contain an implementation and there is Boost.Regex as a compiler independent implementation.

sth
Unfortunately, relying on TR1 features is (most likely) too much of a requirement. The MSVC implementation is not portable (obviously). Boost.Regex is compiler independent, but has too many dependencies (on other boost librarieS).
Frerich Raabe