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 -- Regular expression matching.
12 -- Uses the POSIX regular expression interface in Text.Regex.Posix for now.
14 -----------------------------------------------------------------------------
25 import qualified Text.Regex.Posix as RE
26 import System.IO.Unsafe
30 mkRegex :: String -> Regex
31 mkRegex s = unsafePerformIO (RE.regcomp s RE.regExtended)
33 mkRegexWithOpts :: String -> Bool -> Bool -> Regex
34 mkRegexWithOpts s single_line case_sensitive
35 = unsafePerformIO (RE.regcomp s (RE.regExtended + newline + igcase))
37 newline | single_line = 0
38 | otherwise = RE.regNewline
40 igcase | case_sensitive = 0
41 | otherwise = RE.regIgnoreCase
43 matchRegex :: Regex -> String -> Maybe [String]
45 case (unsafePerformIO (RE.regexec p str)) of
47 Just (before, match, after, sub_strs) -> Just sub_strs
49 matchRegexAll :: Regex -> String ->
50 Maybe ( String, -- \$`
55 matchRegexAll p str = unsafePerformIO (RE.regexec p str)