regex-do-2.6.2: PCRE wrapper

Safe HaskellNone
LanguageHaskell2010

Text.Regex.Do.Pcre.Ascii.Replace

Description

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

Synopsis

Documentation

class Replace pat repl body out where Source

All | Once needs to be specified once with either pat, repl or body

to catch regex construction errors, precompile Regex with makeRegexM or makeRegexOptM

Methods

replace :: pat -> repl -> body -> out Source

Instances

(Regex a, Hint all, Replace' all a repl b) => Replace a (all (repl b)) b b Source

hint repl

>>> replace "^a\\s" (Once (Replacement "A")) "a bc"
(Regex a, Replace' All a repl b) => Replace a (repl b) (All b) b Source

hint Body

(Regex a, Replace' Once a repl b) => Replace a (repl b) (Once b) b Source

hint Body

>>> replace "^a\\s" (Replacement "A") $ Once "a bc"
(Regex a, Hint all, Replace' all a repl b, Functor all) => Replace (all a) (repl b) b b Source

hint Pattern

>>> replace (Once "^a\\s") (Replacement "A") "a bc"
(Regex a, Hint all, Replace' all a repl b) => Replace (all (Pattern a)) (repl b) (Body b) b Source

full typed arg

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

class Replace' all a repl b Source

internal class & instances

use replace instead

Minimal complete definition

replace'

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