headroom-0.4.1.0: License Header Manager
Copyright(c) 2019-2021 Vaclav Svejcar
LicenseBSD-3-Clause
Maintainervaclav.svejcar@gmail.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Headroom.Data.Regex

Description

Extends functionalify provided by Text.Regex.PCRE.Light and Text.Regex.PCRE.Heavy that more suits the needs of this application.

Synopsis

Data Types

newtype Regex Source #

Represents compiled regex, encapsulates the actual implementation.

Constructors

Regex Regex 

Instances

Instances details
Eq Regex Source # 
Instance details

Defined in Headroom.Data.Regex

Methods

(==) :: Regex -> Regex -> Bool #

(/=) :: Regex -> Regex -> Bool #

Show Regex Source # 
Instance details

Defined in Headroom.Data.Regex

Methods

showsPrec :: Int -> Regex -> ShowS #

show :: Regex -> String #

showList :: [Regex] -> ShowS #

FromJSON Regex Source # 
Instance details

Defined in Headroom.Data.Regex

data RegexError Source #

Exception specific to the Headroom.Data.Regex module.

Constructors

CompilationFailed Text Text

given input cannot be compiled as regex

Regex Functions

compile Source #

Arguments

:: 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.

match Source #

Arguments

:: Regex

a PCRE regular expression value produced by compile

-> Text

the subject text to match against

-> Maybe [Text]

the result value

Same as match, but works with Text and uses no additional options.

isMatch Source #

Arguments

:: 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.

replace Source #

Arguments

:: Regex

pattern to replace

-> (Text -> [Text] -> Text)

replacement function (as fullMatch -> [groups] -> result)

-> Text

text to replace in

-> Text

resulting text

Replaces all occurences of given regex.

replaceFirst Source #

Arguments

:: Regex

pattern to replace

-> (Text -> [Text] -> Text)

replacement function (as fullMatch -> [groups] -> result)

-> Text

text to replace in

-> Text

resulting text

Replaces only first occurence of given regex.

scan Source #

Arguments

:: Regex

regex to search for

-> Text

input text

-> [(Text, [Text])]

found occurences (as [(fullMatch, [groups])])

Searches the text for all occurences of given regex.

Unsafe Functions

compileUnsafe Source #

Arguments

:: Text

regex to compile

-> Regex

compiled regex or runtime exception

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.