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"]
- data RegexPattern = Regex [PCREOption] [PCREExecOption] ByteString
- data RegexExecPattern = RegexExec [PCREExecOption] Regex
- class MatchResult x where
- convert :: Maybe [ByteString] -> x
- class RegexLike rl where
- type RegexType rl
- compile :: rl -> Either String (RegexType rl)
- match :: MatchResult res => rl -> ByteString -> res
- (=~) :: (RegexLike regex, MatchResult ret) => ByteString -> regex -> ret
- cfg :: [PCREOption] -> [PCREExecOption] -> ByteString -> RegexPattern
- withExecOpts :: [PCREExecOption] -> Regex -> RegexExecPattern
- caseSensitive :: Bool -> ByteString -> RegexPattern
Documentation
data RegexPattern Source
Uncompiled regular expression with compile and execution options. Compiles to RegexExecPattern preserving execution options.
Constructors
Regex [PCREOption] [PCREExecOption] ByteString |
Instances
data RegexExecPattern Source
Compiled regular expression with execution results.
Constructors
RegexExec [PCREExecOption] Regex |
Instances
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
Instances
class RegexLike rl whereSource
RegexLike types can be compiled to regular epxression or directly used as regular expression.
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.