regex-do-1.1: PCRE regex funs

Safe HaskellNone
LanguageHaskell2010

Regexdo.Pcre.Replace

Synopsis

Documentation

data ReplaceCase Source

Constructors

Once

may be omitted

All

if both Once and All are passed, All prevails

Utf8 
Multiline 

Instances

class Replace_cl a where Source

dynamic group replace

custom replacer fn returns replacement value

>>> replacer::GroupReplacer String
    replacer = defaultReplacer 3 tweak1
          where tweak1 str1 = case str1 of
                               "101" -> "[A]"
                               "3" -> "[Be]"

Once vs All options

>>> replaceGroup [Once] (Needle "(\\w)(=)(\\d{1,3})", replacer) $ Haystack "a=101 b=3 12"

"a=[A] b=3 12"

>>> replaceGroup [All] (Needle "(\\w)(=)(\\d{1,3})", replacer) $ Haystack "a=101 b=3 12"

"a=[A] b=[Be] 12"

static replace for simple (no group) needle

>>> replace [Once,Utf8] (Needle "менее", Replacement  "более") (Haystack "менее менее")

"более менее"

>>> replace [Once,Utf8] (Needle "^a\\s", Replacement "A") (Haystack "a bc хол.гор.")

"Abc хол.гор."

Minimal complete definition

Nothing

Methods

replace :: Mr a => [ReplaceCase] -> (Needle a, Replacement a) -> Haystack a -> a Source

replaceGroup :: Mr a => [ReplaceCase] -> (Needle a, GroupReplacer a) -> Haystack a -> a Source

replaceMatch Source

Arguments

:: Replace_cl' a 
=> (MatchOffset, MatchLength) 
-> (a, a)

(new val, acc passed to GroupReplacer)

-> a

new acc

use in your custom GroupReplacer passed to replaceGroup

see example replacer above or use defaultReplacer

defaultReplacer Source

Arguments

:: (Replace_cl' a, Extract a) 
=> Int

idx of match within a group

-> (a -> a)

(group match -> replacement) tweak

-> GroupReplacer a 

replace with a tweak to specified (by idx) group match

see defaultReplacer source for hints: how to write custom replacer

type Mr a = (Match_cl Regex a, Replace_cl' a, Match_opt a) Source