pugs-hsregex-1.0: Haskell PCRE binding



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



class RegexLike r a | r -> a whereSource

instances of this class may be used as regular expressions with this syntax.


matchTest :: r -> [a] -> BoolSource

Test whether the regex matches at all

matchCount :: r -> [a] -> IntSource

Count the number of times the regex matches

matchAll :: r -> [a] -> [Array Int (Int, Int)]Source

return all matches



:: 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



:: r 
-> String

Used for error messages

class RegexContext x a whereSource


(=~) :: RegexLike r x => [x] -> r -> aSource

match a list against a regular expression, changing its behavior based on its result type.

(=~~) :: (Monad m, RegexLike r x) => [x] -> r -> m aSource

Monadic version of (=~). behaves identically, except it causes the monad to fail when the expression does not match, rather than returning a default value.


RegexContext x () 
RegexContext x Bool 
RegexContext x Int

return number of expressions matched

RegexContext x [Array Int ([x], (Int, Int))] 
RegexContext x [Array Int [x]] 
RegexContext x [[x]] 
RegexContext x [x] 
RegexContext x (MatchResult x) 
RegexContext x (Array Int [x]) 
RegexContext x ([x], [x], [x]) 
RegexContext x ([x], [x], [x], Array Int [x]) 

(!~~) :: RegexLike r x => [x] -> r -> BoolSource

check if regular expression does not match

data MatchResult a Source




mrBefore :: [a]
mrMatch :: [a]
mrAfter :: [a]
mrSubList :: [[a]]
mrSubs :: Array Int [a]