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

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

Example

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 $ "http://stackoverflow.com/questions" =~ url

Documentation

See the API reference.

Performance

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.

Changes

Changes

0.3.4

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

0.3.3.1

Make a release to refresh the haddocks on hackage (see https://github.com/feuerbach/regex-applicative/issues/35).

0.3.3

Add replace

0.3.2.1

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

0.3.2

Add msym

0.3.1

Add comap

0.3.0.3

  • Fix the test suite
  • Fix build with GHC 7.9

0.3.0.2

Fix the test suite

0.3.0.1

Port the test suite to tasty

0.3

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

0.2.1

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

0.2

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

0.1.5

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

0.1.4

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

0.1.3

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

0.1.2

  • Relax the constraint on the containers version

0.1.1

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

0.1

  • Initial release