text-regex-replace-0.1.1.2: Easy replacement when using text-icu regexes.

Data.Text.ICU.Replace

Description

This implements a common DSL for regular expression replacement text. This is represented with the Replace data type. It also implements the IsString interface, so if OverloadedStrings is on, you can use a raw string to build the replacement.

Synopsis

# OverloadedStrings Syntax

The syntax used with OverloadedStrings is meant to be similar to that used in other regular expression libraries in other programming languages.

Generally, input text is considered to be static.

>>> replaceAll "a" "b" "aaa"
"bbb"
>>> replaceAll "ab" "ba" "cdababcd"
"cdbabacd"


However, groups from the regular expression's matches can be insert using $1 (to insert the first group) or ${7} (to insert the seventh group).

>>> replaceAll "(.*), (.*)" "$2$1" "Beeblebrox, Zaphod"
"Zaphod Beeblebrox"
>>> replaceAll "4(\\d)" "${1}4" "7458" "7548"  Dollar signs can be included in the output by doubling them ($$). >>> replaceAll "(\\d+\\.\\d+)" "$$$1" "9.99"
"\$9.99"


# Types

data Replace Source #

A Replace instance is a function from a regular expression match to a Builder. This naturally forms a Monoid, so they're easy to combine.

Replace also implements IsString, so raw strings can be used to construct them.

Instances

 Source # Methods Source # Methodsstimes :: Integral b => b -> Replace -> Replace # Source # Methodsmconcat :: [Replace] -> Replace #

# High-level interface

Arguments

 :: Regex The regular expression to match. -> Replace The specification to replace it with. -> Text The text to operate on. -> Text The text with the first match replaced.

Execute a regular expression on a Text and replace the first match.

Arguments

 :: Replace The specification to replace it with. -> Match The match to replace. -> Text The text with the match replaced.

Replace one regular expression match with the Replace.

Arguments

 :: Regex The regular expression to match. -> Replace The specification to replace it with. -> Text The text to operate on. -> Text The text with all matches replaced.

Execute a regular expression on a Text and replace all matches.

Arguments

 :: Replace The specification to replace it with. -> [Match] The matches to replace. -> Text The text with all matches replaced.

Replace all regular expression matches with the Replace.

# Low-level interface

Arguments

 :: Int The number of the group in a regular expression. -> Replace The Replace that inserts a group's match.

Create a Replace that inserts a regular expression group.

Arguments

 :: Text The static Text to insert. -> Replace The Replace that inserts the static Text.

Create a Replace that inserts static Text.

Arguments

 :: String The static String to insert. -> Replace The Replace that inserts the static String.

Create a Replace that inserts a static String.

Arguments

 :: (Match -> Builder) The function that creates the replacement text. -> Replace The Replace based off that function.

Create a Replace from a function that transforms a Match into a Builder.

Arguments

 :: (Match -> Text) The function that creates the replacement text. -> Replace The Replace based off that function.

Create a Replace From a function that transforms a Match into a Text.

Arguments

 :: Builder The Builder to insert. -> Replace The Replace that inserts the static Builder.

Create a Replace that inserts a static Builder.