Module documentation for 1.0.0.2

pcre-heavy

Finally! A Haskell regular expressions library that does not suck.

based on pcre-light, none of that regex-base complicated pluggable-backend stuff

takes and returns ConvertibleStrings everywhere, use ANY STRING TYPE (String, ByteString, Lazy ByteString, Text, Lazy Text) – but you need a bit more type annotations (or ClassyPrelude‘s asText, asString, etc.) if you use OverloadedStrings which you probably can’t live without

a QuasiQuoter for regexps that does compile time checking (BTW, vim2hs has correct syntax highlighting for that!)

Replacement

sub replaces the first match, gsub replaces all matches.

-- You can use a Stringable type as the replacement...
>>> gsub [re|\d+|] "!!!NUMBER!!!" "Copyright (c) 2015 The 000 Group"
"Copyright (c) !!!NUMBER!!! The !!!NUMBER!!! Group"
-- or a (Stringable a => [a] -> a) function -- that will get the groups...
>>> gsub [re|%(\d+)(\w+)|] (\(d:w:_) -> "{" ++ d ++ " of " ++ w ++ "}" :: String) "Hello, %20thing"
"Hello, {20 of thing}"
-- or a (Stringable a => a -> a) function -- that will get the full match...
>>> gsub [re|-\w+|] (\x -> "+" ++ (reverse $ drop 1 x) :: String) "hello -world"
"hello +dlrow"
-- or a (Stringable a => a -> [a] -> a) function.
-- That will get both the full match and the groups.
-- I have no idea why you would want to use that, but that's there :-)