cregex
cregex copied to clipboard
A small implementation of regular expression matching engine in C
cregex
cregex is a compact implementation of regular expression
(regex) matching engine in C. Its design was inspired by Rob Pike's regex-code for the book "Beautiful Code"
available online here.
It is based on two papers by Russ Cox:
- Regular Expression Matching Can Be Simple And Fast
- Regular Expression Matching: the Virtual Machine Approach
cregex supports a subset of the syntax and semantics of the POSIX Basic Regular Expressions.
The main design goal of cregex is to be small, correct, self contained and
use few resources while retaining acceptable performance and feature completeness.
Features
^and$anchors.match any single character[...]and[^...]character classes?,*,+, and{x,y}greedy quantifiers??,*?,+?, and{x,y}?non-greedy quantifiers(...)capturing groups
Build and Test
Simply run to build the library and test programs.
$ make
Run the tests from Go distribution.
$ make check
Visualize the regular expressions with Graphviz.
$ tests/re2dot "(a*)(b{0,1})(b{1,})b{3}" | dot -Tpng -o out.png
License
cregex is freely redistributable under the BSD 2 clause license.
Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.