Safe Haskell | None |
---|---|
Language | Haskell2010 |
- (*=~) :: IsRegex RE s => s -> RE -> Matches s
- (?=~) :: IsRegex RE s => s -> RE -> Match s
- (*=~/) :: IsRegex RE s => s -> SearchReplace RE s -> s
- (?=~/) :: IsRegex RE s => s -> SearchReplace RE s -> s
- data Matches a
- matchesSource :: Matches a -> a
- allMatches :: Matches a -> [Match a]
- anyMatches :: Matches a -> Bool
- countMatches :: Matches a -> Int
- matches :: Matches a -> [a]
- data Match a
- matchSource :: Match a -> a
- matched :: Match a -> Bool
- matchedText :: Match a -> Maybe a
- data RE
- reSource :: RE -> String
- data SimpleREOptions
- data SearchReplace re s = SearchReplace {
- getSearch :: !re
- getTemplate :: !s
- compileRegex :: (Functor m, Monad m) => String -> m RE
- compileRegexWith :: (Functor m, Monad m) => SimpleREOptions -> String -> m RE
- compileSearchReplace :: (Monad m, Functor m, IsRegex RE s) => String -> String -> m (SearchReplace RE s)
- compileSearchReplaceWith :: (Monad m, Functor m, IsRegex RE s) => SimpleREOptions -> String -> String -> m (SearchReplace RE s)
- escape :: (Functor m, Monad m) => (String -> String) -> String -> m RE
- escapeWith :: (Functor m, Monad m) => SimpleREOptions -> (String -> String) -> String -> m RE
- escapeREString :: String -> String
- (=~) :: (RegexContext Regex s a, RegexMaker Regex CompOption ExecOption s) => s -> RE -> a
- (=~~) :: (Monad m, RegexContext Regex s a, RegexMaker Regex CompOption ExecOption s) => s -> RE -> m a
- class Replace s => IsRegex re s where
- module Text.RE.ZeInternals.TDFA
- module Text.RE.ZeInternals.SearchReplace.TDFA
- module Text.RE.TDFA.ByteString
- module Text.RE.TDFA.ByteString.Lazy
- module Text.RE.TDFA.Sequence
- module Text.RE.TDFA.String
- module Text.RE.TDFA.Text
- module Text.RE.TDFA.Text.Lazy
Tutorial
We have a regex tutorial at http://tutorial.regex.uk.
About this Module
This module provides access to the back end through polymorphic functions that operate over all of the String/Text/ByteString types supported by the back end. If you don't need this generality then you might want to consider using one of the modules that have been specialised for each of these types:
The Match Operators
(*=~) :: IsRegex RE s => s -> RE -> Matches s Source #
find all the matches in the argument text; e.g., to count the number of naturals in s:
countMatches $ s *=~ [re|[0-9]+|]
(?=~) :: IsRegex RE s => s -> RE -> Match s Source #
find the first match in the argument text; e.g., to test if there is a natural number in the input text:
matched $ s ?=~ [re|[0-9]+|]
The SearchReplace Operators
(*=~/) :: IsRegex RE s => s -> SearchReplace RE s -> s Source #
search and replace all matches in the argument text; e.g., this section will convert every YYYY-MM-DD format date in its argument text into a DD/MM/YYYY date:
(*=~/ [ed|${y}([0-9]{4})-0*${m}([0-9]{2})-0*${d}([0-9]{2})///${d}/${m}/${y}|])
(?=~/) :: IsRegex RE s => s -> SearchReplace RE s -> s Source #
search and replace the first occurrence only
Matches
the result type to use when every match is needed, not just the first match of the RE against the source
Functor Matches Source # | |
(RegexContext regex source [MatchText source], RegexLike regex source) => RegexContext regex source (Matches source) Source # | this instance hooks |
Eq a => Eq (Matches a) Source # | |
Show a => Show (Matches a) Source # | |
matchesSource :: Matches a -> a Source #
the source text being matched
anyMatches :: Matches a -> Bool Source #
tests whether the RE matched the source text at all
countMatches :: Matches a -> Int Source #
count the matches
Match
the result of matching a RE to a text once, listing the text that was matched and the named captures in the RE and all of the substrings matched, with the text captured by the whole RE; a complete failure to match will be represented with an empty array (with bounds (0,-1))
Functor Match Source # | |
(RegexContext regex source (AllTextSubmatches (Array Int) (source, (Int, Int))), RegexLike regex source) => RegexContext regex source (Match source) Source # | this instance hooks |
Eq a => Eq (Match a) Source # | |
Show a => Show (Match a) Source # | |
matchSource :: Match a -> a Source #
the whole source text
matchedText :: Match a -> Maybe a Source #
tests whether the RE matched the source text at all
The RE
Type
the RE type for this back end representing a well-formed, compiled RE
Options
data SimpleREOptions Source #
the default API uses these simple, universal RE options,
which get auto-converted into the apropriate back-end REOptions_
MultilineSensitive | case-sensitive with ^ and $ matching the start and end of a line |
MultilineInsensitive | case-insensitive with ^ and $ matsh the start and end of a line |
BlockSensitive | case-sensitive with ^ and $ matching the start and end of the input text |
BlockInsensitive | case-insensitive with ^ and $ matching the start and end of the input text |
Bounded SimpleREOptions Source # | |
Enum SimpleREOptions Source # | |
Eq SimpleREOptions Source # | |
Ord SimpleREOptions Source # | |
Show SimpleREOptions Source # | |
Lift SimpleREOptions Source # | we need to use this in the quasi quoters to specify |
Compiling and Escaping REs
data SearchReplace re s Source #
contains a compiled RE and replacement template
SearchReplace | |
|
Functor (SearchReplace re) Source # | |
(Show s, Show re) => Show (SearchReplace re s) Source # | |
compileRegexWith :: (Functor m, Monad m) => SimpleREOptions -> String -> m RE Source #
compileSearchReplace :: (Monad m, Functor m, IsRegex RE s) => String -> String -> m (SearchReplace RE s) Source #
compile a SearchReplace template generating errors if the RE or the template are not well formed, all capture references being checked
compileSearchReplaceWith :: (Monad m, Functor m, IsRegex RE s) => SimpleREOptions -> String -> String -> m (SearchReplace RE s) Source #
compile a SearchReplace template, with simple options, generating errors if the RE or the template are not well formed, all capture references being checked
escape :: (Functor m, Monad m) => (String -> String) -> String -> m RE Source #
convert a string into a RE that matches that string, and apply it to an argument continuation function to make up the RE string to be compiled; e.g., to compile a RE that will only match the string:
maybe undefined id . escape (("^"++) . (++"$"))
escapeWith :: (Functor m, Monad m) => SimpleREOptions -> (String -> String) -> String -> m RE Source #
a variant of escape
where the SimpleREOptions
are specified
escapeREString :: String -> String Source #
Convert a string into a regular expression that will match that string
The Classic rexex-base Match Operators
(=~) :: (RegexContext Regex s a, RegexMaker Regex CompOption ExecOption s) => s -> RE -> a Source #
the regex-base polymorphic match operator
(=~~) :: (Monad m, RegexContext Regex s a, RegexMaker Regex CompOption ExecOption s) => s -> RE -> m a Source #
the regex-base monadic, polymorphic match operator
IsRegex
class Replace s => IsRegex re s where Source #
the IsRegex
class allows polymorhic tools to be written that
will work with a variety of regex back ends and text types
matchOnce :: re -> s -> Match s Source #
finding the first match
matchMany :: re -> s -> Matches s Source #
finding all matches
makeRegex :: (Functor m, Monad m) => s -> m re Source #
compiling an RE, failing if the RE is not well formed
makeRegexWith :: (Functor m, Monad m) => SimpleREOptions -> s -> m re Source #
comiling an RE, specifying the SimpleREOptions
makeSearchReplace :: (Functor m, Monad m, IsRegex re s) => s -> s -> m (SearchReplace re s) Source #
compiling a SearchReplace
template from the RE text and the template Text, failing if they are not well formed
makeSearchReplaceWith :: (Functor m, Monad m, IsRegex re s) => SimpleREOptions -> s -> s -> m (SearchReplace re s) Source #
compiling a SearchReplace
template specifing the SimpleREOptions
for the RE
makeEscaped :: (Functor m, Monad m) => (s -> s) -> s -> m re Source #
incorporate an escaped string into a compiled RE with the default options
makeEscapedWith :: (Functor m, Monad m) => SimpleREOptions -> (s -> s) -> s -> m re Source #
incorporate an escaped string into a compiled RE with the specified SimpleREOptions
regexSource :: re -> s Source #
extract the text of the RE from the RE
The Quasi Quoters and Minor Functions
The [re|.*|]
quasi quoters, with variants for specifing different
options to the RE compiler (see Text.RE.REOptions), and the
specialised back-end types and functions.
module Text.RE.ZeInternals.TDFA
The [ed|.*///foo|]
quasi quoters, with variants for specifing different
options to the RE compiler (see Text.RE.REOptions).
The Operator Instances
These modules merely provide the IsRegex
instances.
module Text.RE.TDFA.ByteString
module Text.RE.TDFA.ByteString.Lazy
module Text.RE.TDFA.Sequence
module Text.RE.TDFA.String
module Text.RE.TDFA.Text
module Text.RE.TDFA.Text.Lazy