[Haskell-cafe] ANNOUNCE: pcre-light, a light, portable regular expression library for Haskell

Don Stewart dons at galois.com
Sat Jan 12 23:19:23 EST 2008

    A light regular expression library, using Perl 5 compatible regexes

I'm pleased to announce the first release of pcre-light.  This library
provides a simple, efficient interface to PCRE regular expressions, via
either strict ByteStrings or classical Strings.

Compilation and matching of regular expressions is done via two

    compile :: ByteString -> [PCREOption] -> Either String Regex
    match   :: Regex -> ByteString -> [PCREExecOption] -> Maybe [ByteString]

A convenience interface for 'Char8' Strings is also provided.

== Examples ==

Although the operations by default take ByteStrings, we can avoid unnecessary 'pack' calls
using GHC's support for ByteStrings literals, enabled with -XOverloadedStrings:

    > :m + Text.Regex.PCRE.Light 
    > :m + Data.ByteString.Char8 
    > :set -XOverloadedStrings 

    > let Right r = compile "the quick brown fox" []

    > match r "the quick brown fox" []
    Just ["the quick brown fox"]

    > match r "the quick brown FOX" []

We can also enable various matching extensions,

   > let Right r = compile "the quick brown fox" [caseless]

   > match r "the quick brown FOX" []
   Just ["the quick brown FOX"]

Subpatterns, and fancy Perl regex extensions are happily supported:

   > let Right r = compile "^(abc){1,2}zz" []
   > match r "abczz"  []
   Just ["abczz","abc"]

Where the subpattern bound by ( ) was returned as the second element of the list.

   > let Right r = compile "\\w+(?=\t)" []
   > match r "the quick brown\t fox" []
   Just ["brown"]

You can do lots of silly things with this:

   > let Right r = compile "^(a()+)+" []
   > match r "aaaa"
   Just ["aaaa", "a", ""]

The full set of compile and runtime PCRE extensions are supported.

== Get it ==
* Stable tarballs, (on Hackage, of course):


* Cabal install it!

Using the new 'cabal-install', you can automatically download, build and
install the package:

    $ cabal update

    $ cabal install pcre-light
    Downloading 'pcre-light-0.1'...
    Configuring pcre-light-0.1...
    Preprocessing library pcre-light-0.1...
    Building pcre-light-0.1...
    Registering pcre-light-0.1..

And off we go!

For more information about cabal-install, see the hackage page for this
excellent tool.

* Darcs repository:


* Documentation:


* Stability

The library takes correctness seriously, and comes with a reasonable
testsuite (with plans to greatly extend it), and code coverage data for
those tests (using GHC's new -fhpc flag). You can see the test coverage
results here:


Yours in code,

P.S. I'd like to encourage other authors to distribute code coverage results
for their libraries! hpc is an invaluable tool to ensure high quality libraries
for the Haskell community.

P.P.S. Consider consider contributing your own light bindings to useful C
libraries. The more we have, the more certain and sustainable Haskell
development will be :)

P.P.P.S. Thanks to #haskell for testing and advice.

More information about the Haskell-Cafe mailing list