Copyright | (c) 2019-2021 Vaclav Svejcar |
---|---|
License | BSD-3-Clause |
Maintainer | vaclav.svejcar@gmail.com |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
Extends functionalify provided by Text.Regex.PCRE.Light and Text.Regex.PCRE.Heavy that more suits the needs of this application.
Synopsis
- newtype Regex = Regex Regex
- data RegexError = CompilationFailed Text Text
- compile :: MonadThrow m => Text -> m Regex
- match :: Regex -> Text -> Maybe [Text]
- isMatch :: Regex -> Text -> Bool
- re :: QuasiQuoter
- replace :: Regex -> (Text -> [Text] -> Text) -> Text -> Text
- replaceFirst :: Regex -> (Text -> [Text] -> Text) -> Text -> Text
- scan :: Regex -> Text -> [(Text, [Text])]
- compileUnsafe :: Text -> Regex
Data Types
Represents compiled regex, encapsulates the actual implementation.
data RegexError Source #
Exception specific to the Headroom.Data.Regex module.
CompilationFailed Text Text | given input cannot be compiled as regex |
Instances
Show RegexError Source # | |
Defined in Headroom.Data.Regex showsPrec :: Int -> RegexError -> ShowS # show :: RegexError -> String # showList :: [RegexError] -> ShowS # | |
Exception RegexError Source # | |
Defined in Headroom.Data.Regex toException :: RegexError -> SomeException # fromException :: SomeException -> Maybe RegexError # displayException :: RegexError -> String # |
Regex Functions
:: MonadThrow m | |
=> Text | regex to compile |
-> m Regex | compiled regex |
Compiles given regex in runtime. If possible, prefer the re
quasi quotation version that does the same at compile time.
:: Regex | a PCRE regular expression value produced by compile |
-> Text | the subject text to match against |
-> Bool | the result value |
Same as match
, but instead of returning matched text it only indicates
whether the given text matches the pattern or not.
re :: QuasiQuoter Source #
A QuasiQuoter for regular expressions that does a compile time check.
:: Regex | pattern to replace |
-> (Text -> [Text] -> Text) | replacement function (as |
-> Text | text to replace in |
-> Text | resulting text |
Replaces all occurences of given regex.
:: Regex | pattern to replace |
-> (Text -> [Text] -> Text) | replacement function (as |
-> Text | text to replace in |
-> Text | resulting text |
Replaces only first occurence of given regex.
:: Regex | regex to search for |
-> Text | input text |
-> [(Text, [Text])] | found occurences (as |
Searches the text for all occurences of given regex.
Unsafe Functions
Compiles the given text into regex in runtime. Note that if the regex cannot be compiled, it will throw runtime error. Do not use this function unless you know what you're doing.