pcre-light-extra-0.0.0: pcre-light extra functionality

Text.Regex.PCRE.Light.Extra

Description

pcre-light utility functions for more user friendly usage. Instead of adding execution and compile options to the matching and compiling functions, the options are added to the regular expression to be compiled or run. Furthermore support for different matching return types (using typeclass MatchResult) and different regular expression types (compiled or uncompiled using typeclass RegexLike) are supported.

examples using GHC's -XOverloadedStrings flag:

simple matching with uncompiled pattern abc of type ByteString:

>>> ("abc" =~ ("abc" :: ByteString)) :: Bool
True

case insensitive matching with uncompiled pattern of type ByteString:

>>> ("AbCasf" =~ caseSensitive False "abc") :: Bool
True
>>> ("AbCasf" =~ caseSensitive False "abc") :: Maybe [ByteString]
Just ["AbC"]

Synopsis

Documentation

data RegexPattern Source

Uncompiled regular expression with compile and execution options. Compiles to RegexExecPattern preserving execution options.

data RegexExecPattern Source

Compiled regular expression with execution results.

class MatchResult x whereSource

Typeclass defining automatic conversion of PCRE matching results to user defined type. Used in typeclass RegexLike and function (=~).

Methods

convert :: Maybe [ByteString] -> xSource

class RegexLike rl whereSource

RegexLike types can be compiled to regular epxression or directly used as regular expression.

Associated Types

type RegexType rl Source

Type of compiled regular expression for instance rl.

Methods

compile :: rl -> Either String (RegexType rl)Source

compiles a perl-compatible regular expression to an executable regular expression. See Text.Regex.PCRE.Light.compileM.

match :: MatchResult res => rl -> ByteString -> resSource

matches a Bytestring with a regular expression of type rl. If rl needs to be compiled (for example when rl ~ ByteString or rl ~ RegexPattern) but is invalid, an exception will be thrown. It is recommended to use compiled patterns with match for better error handling.

(=~) :: (RegexLike regex, MatchResult ret) => ByteString -> regex -> retSource

matches a ByteString with a regular expression.

cfg :: [PCREOption] -> [PCREExecOption] -> ByteString -> RegexPatternSource

create regular expression with compile and execution options.

withExecOpts :: [PCREExecOption] -> Regex -> RegexExecPatternSource

Add execution options to compiled regular expression of pcre-light's compiled regular expression type Regex

caseSensitive :: Bool -> ByteString -> RegexPatternSource

Create case sensitive (first parameter is True) or case insensitive regular expression from pattern.