1 -----------------------------------------------------------------------------
4 A simple high-level interface to Regex
7 -----------------------------------------------------------------------------
9 > module RegexString (Regex(..), mkRegex, matchRegex) where
16 > type Regex = PatBuffer
18 > mkRegex :: String -> Regex
19 > mkRegex s = unsafePerformPrimIO (
20 > re_compile_pattern (packString s) False False)
22 > matchRegex :: Regex -> String -> Maybe [String]
23 > matchRegex p s = unsafePerformPrimIO (
24 > re_match p str 0 True >>= \m ->
26 > Nothing -> return Nothing
27 > Just m -> return (Just (matches m str))
32 > matches (REmatch arr _ _ _ _) s =
33 > [ unpackPS (substrPS s beg (end-1)) |
34 > index <- [1..], let (beg,end) = arr ! index ]