1 -----------------------------------------------------------------------------
4 -- Copyright : (c) The University of Glasgow 2001
5 -- License : BSD-style (see the file libraries/core/LICENSE)
7 -- Maintainer : libraries@haskell.org
8 -- Stability : experimental
9 -- Portability : non-portable (only on platforms that provide a regex lib)
11 -- $Id: Regex.hs,v 1.1 2001/08/02 11:20:50 simonmar Exp $
13 -- Regular expression matching.
14 -- Uses the POSIX regular expression interface in Text.Regex.Posix for now.
16 -----------------------------------------------------------------------------
27 import qualified Text.Regex.Posix as RE
28 import System.IO.Unsafe
32 mkRegex :: String -> Regex
33 mkRegex s = unsafePerformIO (RE.regcomp s RE.regExtended)
35 mkRegexWithOpts :: String -> Bool -> Bool -> Regex
36 mkRegexWithOpts s single_line case_sensitive
37 = unsafePerformIO (RE.regcomp s (RE.regExtended + newline + igcase))
39 newline | single_line = 0
40 | otherwise = RE.regNewline
42 igcase | case_sensitive = 0
43 | otherwise = RE.regIgnoreCase
45 matchRegex :: Regex -> String -> Maybe [String]
47 case (unsafePerformIO (RE.regexec p str)) of
49 Just (before, match, after, sub_strs) -> Just sub_strs
51 matchRegexAll :: Regex -> String ->
57 matchRegexAll p str = unsafePerformIO (RE.regexec p str)