| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Text.Regex.Do.Pcre.ReplaceOpen
Description
extensible and reusable replacement functions
Run replacement with your preferred content types e.g. Data.Text, from search results with non-PCRE regex or non-regex libs
open a bug or a PR on git to request a new Extract' instance
Data.Text instance already works
>>>replace (Just $ toArray [(4,3)]) (Replacement "4567") (Body "abc 123 def"::Body Text)
"abc 4567 def"
GroupReplacer can be used too
- class ReplaceOpen f r where
- replace :: Extract' a => f MatchArray -> r a -> Body a -> a
- toArray :: [PosLen] -> MatchArray
- class Extract a => Extract' a where
- defaultReplacer :: Extract' a => Int -> (a -> a) -> GroupReplacer a
- getGroup :: Extract a => ReplaceAcc a -> MatchArray -> Int -> Maybe a
- replaceMatch :: Extract' a => PosLen -> (a, ReplaceAcc a) -> ReplaceAcc a
Documentation
class ReplaceOpen f r where Source
Methods
replace :: Extract' a => f MatchArray -> r a -> Body a -> a Source
toArray :: [PosLen] -> MatchArray Source
class Extract a => Extract' a where Source
see String, ByteString instances for implementation examples
see Text.Regex.Base.RegexLike for Extract detail
Arguments
| :: Extract' a | |
| => Int | group idx |
| -> (a -> a) | (group match -> replacement) tweak |
| -> GroupReplacer a |
Replaces specified (by idx) group match with tweaked value. Works for one common simple use case
GroupReplacer can be used with complicated regex
another custom dynamic replacer could e.g. inspect all group matches before looking up a replacement.
getGroup :: Extract a => ReplaceAcc a -> MatchArray -> Int -> Maybe a Source
get group content safely
see defaultReplacer source for use example
Arguments
| :: Extract' a | |
| => PosLen | replaceable, unadjusted |
| -> (a, ReplaceAcc a) | (new val, acc passed to |
| -> ReplaceAcc a | new acc |
call from your custom GroupReplacer passed to replaceGroup
see defaultReplacer source for use example