RRegex.Syntax

|  | Contents | Index
RRegex.Syntax
Description
basic usage: string =~ 'regular expression' returns different things depending on context type - what it evaluates to --------------------------- Int - number of times the regular expression matches String - matching portion of string (String,String,String) - (text before match, matching text, text after match) [Either String String] - list of matching and nonmatching strings, if concated, the original string results. Left = notmatching, Right = matching. Bool - whether the string matches () - always returns () (useful in monad context, see below) [String] - list of matches Array Int String - list of substring matches for first match (String, Array Int String) - full matching text and substring matches [(String, Array Int String)] - all matches, full match plus substrings [Array Int String] - all substrings from all matches also, there is the monadic version (=~~) which always behaves exactly the same as (=~) except when the match fails, instead of returning a default value, the monad fails. regular expressions: these may be strings, which are interpreted as regular expressions, or Regex's from the Text.Regex module. or any other instance of the RegexLike class. when using strings, you may prefix the regex by (?flags) where flags is one of i for a case insensitive match and m means a multi-line match. other flags may be available depending on your implementation advanced features: not just strings can be matched, but rather lists of anything a matcher is defined for. RegexLikeImp data class can be used for in-place code generated by template haskell for compile-time checked regular expresions
Synopsis
class RegexLike r a | r -> a where
matchTest :: r -> [a] -> Bool
matchCount :: r -> [a] -> Int
matchAll :: r -> [a] -> [Array Int (Int, Int)]
matchOnce :: r -> [a] -> Bool -> Maybe (Array Int (Int, Int))
matchShow :: r -> String
class RegexContext x a where
(=~) :: RegexLike r x => [x] -> r -> a
(=~~) :: (Monad m, RegexLike r x) => [x] -> r -> m a
(!~) :: RegexLike r x => [x] -> r -> Bool
data MatchResult a = MR {
mrBefore :: [a]
mrMatch :: [a]
mrAfter :: [a]
mrSubList :: [[a]]
mrSubs :: (Array Int [a])
}
Documentation
class RegexLike r a | r -> a where
instances of this class may be used as regular expressions with this syntax.
Methods
matchTest :: r -> [a] -> Bool
Test whether the regex matches at all
matchCount :: r -> [a] -> Int
Count the number of times the regex matches
matchAll :: r -> [a] -> [Array Int (Int, Int)]
return all matches
matchOnce
:: r | Regular Expression
-> [a] | String to match
-> Bool | Whether we are at the begining of the string (as opposed to continuing a previous match)
-> Maybe (Array Int (Int, Int)) | array of matched expression
match once
matchShow
:: r |
-> String | Used for error messages
Instances
RegexLike Regex Char
RegexLike String Char
class RegexContext x a where
Methods
(=~) :: RegexLike r x => [x] -> r -> a
match a list against a regular expression, changing its behavior based on its result type.
(=~~) :: (Monad m, RegexLike r x) => [x] -> r -> m a
Monadic version of (=~). behaves identically, except it causes the monad to fail when the expression does not match, rather than returning a default value.
Instances
RegexContext x Int
RegexContext x ([x], [x], [x])
RegexContext x ([x], [x], [x], Array Int [x])
RegexContext x (MatchResult x)
RegexContext x [x]
RegexContext x Bool
RegexContext x ()
RegexContext x [[x]]
RegexContext x [Array Int [x]]
RegexContext x [Array Int ([x], (Int, Int))]
RegexContext x (Array Int [x])
(!~) :: RegexLike r x => [x] -> r -> Bool
check if regular expression does not match
data MatchResult a
Constructors
MR |
mrBefore :: [a] |
mrMatch :: [a] |
mrAfter :: [a] |
mrSubList :: [[a]] |
mrSubs :: (Array Int [a]) |
Instances
RegexContext x (MatchResult x)
Produced by Haddock version ADDOCK_VERSION