MIT licensed by Roman Cheplyaka
Maintained by Roman Cheplyaka
This version can be pinned in stack with:regex-applicative-0.3.4@sha256:a8a15d4e053bab8e97428c62c9c2afa2420ad4e67f87e9bec64a22b3cc0e9f48,2609


regex-applicative is a parsing combinator library for Haskell based on regular expressions.


import Text.Regex.Applicative

data Protocol = HTTP | FTP deriving Show

protocol :: RE Char Protocol
protocol = HTTP <$ string "http" <|> FTP <$ string "ftp"

type Host = String
type Location = String
data URL = URL Protocol Host Location deriving Show

host :: RE Char Host
host = many $ psym $ (/= '/')

url :: RE Char URL
url = URL <$> protocol <* string "://" <*> host <* sym '/' <*> many anySym

main = print $ "" =~ url


See the API reference.


For common tasks, this package is several times slower than monadic parser combinator libraries like parsec. However, this library has a roughly linear complexity, whereas monadic parser combinators have exponential worst-time complexity (see here).

Some tips to make your regex run faster:

  1. If you don’t care about the result of the whole regex or its part, only whether it matches or not, mark it with void or <$. Recognition is faster than parsing.

  2. If you apply the same regex to multiple strings, partially apply it like so:

    let matcher = match my_regex
    in  map matcher my_strings

    This way the compiled regex is stored in the matcher value and shared among the strings.

GHC support

Only GHC versions >= 8.0 are supported, although older versions may work too.




  • Let the user provide a custom uncons function (add find{First,Longest,Shortest}PrefixWithUncons)
  • Add Filtrable and Monoid instances for RE

Make a release to refresh the haddocks on hackage (see


Add replace

  • Use strict left fold in decimal/hexadecimal
  • Include a missing test module in the sdist tarball


Add msym


Add comap

  • Fix the test suite
  • Fix build with GHC 7.9

Fix the test suite

Port the test suite to tasty


  • Add a new module, Text.Regex.Applicative.Common, which contains some commonly used regexps (by Aleksey Khudyakov)
  • Improve the test suite


  • Add the withMatched function
  • Make matching functions a bit more lax
  • Fix a bug in the empty method


  • Infix matching functions
  • Improved documentation
  • Improved performance
  • Improved portability


  • Expose Object interface
  • Allow matching prefixes rather than the whole string
  • Add non-greedy repetitions


  • Completely rewrite the engine. Now it’s faster and runs in constant space.
  • Add ‘string’ function and ‘IsString’ instance.


  • Fix a .cabal-file issue introduced in 0.1.2
  • Change the fixity of =~


  • Relax the constraint on the containers version


  • Fix a bug in ‘reFoldl’ and ‘many’
  • “Lazy” infinite regexes are no longer supported


  • Initial release