{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
module Text.Regex (
Regex,
mkRegex,
mkRegexWithOpts,
matchRegex,
matchRegexAll
) where
import Text.Regex.Base(RegexMaker(makeRegexOpts),defaultCompOpt,defaultExecOpt,RegexContext(matchM))
import Text.Regex.TDFA(Regex,caseSensitive,multiline,newSyntax)
mkRegex :: String -> Regex
mkRegex :: String -> Regex
mkRegex String
s = forall regex compOpt execOpt source.
RegexMaker regex compOpt execOpt source =>
compOpt -> execOpt -> source -> regex
makeRegexOpts CompOption
opt forall regex compOpt execOpt.
RegexOptions regex compOpt execOpt =>
execOpt
defaultExecOpt String
s
where opt :: CompOption
opt = forall regex compOpt execOpt.
RegexOptions regex compOpt execOpt =>
compOpt
defaultCompOpt { newSyntax :: Bool
newSyntax = Bool
True, multiline :: Bool
multiline = Bool
True }
mkRegexWithOpts
:: String
-> Bool
-> Bool
-> Regex
mkRegexWithOpts :: String -> Bool -> Bool -> Regex
mkRegexWithOpts String
s Bool
single_line Bool
case_sensitive
= let opt :: CompOption
opt = forall regex compOpt execOpt.
RegexOptions regex compOpt execOpt =>
compOpt
defaultCompOpt
{ multiline :: Bool
multiline = (if Bool
single_line then Bool
True else Bool
False)
, caseSensitive :: Bool
caseSensitive = (if Bool
case_sensitive then Bool
True else Bool
False)
, newSyntax :: Bool
newSyntax = Bool
True }
in forall regex compOpt execOpt source.
RegexMaker regex compOpt execOpt source =>
compOpt -> execOpt -> source -> regex
makeRegexOpts CompOption
opt forall regex compOpt execOpt.
RegexOptions regex compOpt execOpt =>
execOpt
defaultExecOpt String
s
matchRegex
:: Regex
-> String
-> Maybe [String]
matchRegex :: Regex -> String -> Maybe [String]
matchRegex Regex
p String
str = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(String
_,String
_,String
_,[String]
str) -> [String]
str) (Regex -> String -> Maybe (String, String, String, [String])
matchRegexAll Regex
p String
str)
matchRegexAll
:: Regex
-> String
-> Maybe ( String, String, String, [String] )
matchRegexAll :: Regex -> String -> Maybe (String, String, String, [String])
matchRegexAll Regex
p String
str = forall regex source target (m :: * -> *).
(RegexContext regex source target, MonadFail m) =>
regex -> source -> m target
matchM Regex
p String
str