This is a simple public domain regex engine library and command-line tool, implemented in the C programming language without any external dependencies aside from the C standard library. It is far from full-featured, and there are currently still some known bugs (listed here). For information about the internals of this project, check the contents of the doc directory. Online documentation for the libemregex API can be found here.
- The following dependencies are needed: a C compiler and CMake. To run the tests you also need Ruby.
- Run
cmake -G "Unix Makefiles" .
to generate a build system. If you wish to compile a release build with optimizations, add the flag-DCMAKE_BUILD_TYPE=Release
to the command. - Run
make
to build everything. This will generate anemregex
executable in the project root directory. - Run
ctest --output-on-failure
to run the tests, reporting any errors in case of test failure.make test
can also be used to run the tests, but it doesn't print any error messages for failing test cases.
The emregex
executable works pretty much like grep
, except
that it matches the whole input string, and currently only reads
from standard input. This means that the most useful way to use
it is to pipe something to it, e.g. like this:
echo "text to match" | ./emregex "regex pattern"
The program prints match
and exits with the status 0 if the
given string matches the regex passed as the argument, or
no match
with a non-zero exit status if it doesn't.
You can also print the abstract syntax tree of the parsed regex
pattern by invoking emregex
with the --print-ast
flag. This
might be useful for e.g. debugging the program.