regex-do-2.5: PCRE wrapper

Safe HaskellNone
LanguageHaskell2010

Text.Regex.Do.Pcre.Ascii.Replace

Description

Ascii vs Utf8 modules

for reliable results with Utf8 pattern or body, use Text.Regex.Do.Pcre.Utf8.Replace

Documentation

class Replace all a repl b where Source

Methods

replace :: (R_ b, Matchf all b) => all (Pattern a) -> repl b -> Body b -> b Source

Instances

Repl_ [] a repl b => Replace All a repl b Source

to tweak regex with Comp or Exec, see Text.Regex.Do.Type.Regex

dynamic group replace

custom replacer fn returns replacement value. See defaultReplacer

>>> replacer::GroupReplacer String
    replacer = defaultReplacer 1 tweak1
          where tweak1 str1 = case str1 of
                                "101" -> "[1 0 1]"
                                "3" -> "[ 3 ]"
                                otherwise -> trace str1 "?"
>>> replace (All (Pattern "\\w=(\\d{1,3})")) replacer $ Body "a=101 b=3 12"

"a=[1 0 1] b=[ 3 ] 12"

Repl_ Maybe a repl b => Replace Once a repl b Source

static replace for simple (no group) needle

for no-regex ByteString replacement see Text.Regex.Do.Split

>>> replace (Once (Pattern "^a\\s")) (Replacement "A") (Body "a bc")

"Abc"

dynamic group replace

>>> replace (Once (Pattern "\\w=(\\d{1,3})")) replacer $ Body "a=101 b=3 12"

"a=[1 0 1] b=3 12"

type Repl_ f rx r a = (Regex rx, RegexLike Regex a, Extract' a, ReplaceOpen f r) Source