regex-do-2.5: PCRE wrapper

Safe HaskellSafe
LanguageHaskell2010

Text.Regex.Do.Type.MatchHint

Documentation

newtype Test a Source

Constructors

Test a

test: does body match pattern?

Instances

Hint Test Source 
MatchHint Test String Source 
MatchHint Test ByteString Source
>>> Test ("в"::ByteString) =~ "тихо в лесу"

True

MatchHint Test Utf8_ String Source 
MatchHint Test Utf8_ ByteString Source
>>> Test (toByteString "в") =~ toByteString "тихо в лесу"

True

type F Test String = Bool Source 
type F Test ByteString = Bool Source 
type F Test String = Bool Source 
type F Test ByteString = Bool Source 

newtype Once a Source

Constructors

Once a

values

Instances

Functor Once Source 
Applicative Once Source 
Hint Once Source 
Matchf Once b Source 
MatchHint Once String Source
>>> Once ("^all"::String) =~ "all the time"

["all"]

MatchHint Once ByteString Source 
MatchHint Once Utf8_ String Source
>>> Once ("^all"::String) =~ "all the time"

["all"]

MatchHint Once Utf8_ ByteString Source 
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"

Replace Once Utf8_ String Replacement Source 
Replace Once Utf8_ ByteString Replacement Source 
Replace Once Utf8_ ByteString GroupReplacer Source 
type H Once = Maybe MatchArray Source 
type P Once = Maybe [PosLen] Source 
type F Once String = [String] Source 
type F Once ByteString = [ByteString] Source 
type F Once String = [String] Source 
type F Once ByteString = [ByteString] Source 

newtype All a Source

Constructors

All a

values

Instances

Functor All Source 
Applicative All Source 
Hint All Source 
Matchf All b Source 
MatchHint All String Source 
MatchHint All ByteString Source 
MatchHint All Utf8_ String Source 
MatchHint All Utf8_ ByteString Source 
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"

Replace All Utf8_ String Replacement Source 
Replace All Utf8_ ByteString Replacement Source 
Replace All Utf8_ ByteString GroupReplacer Source
>>> replacer::GroupReplacer (Utf8_ ByteString)
        replacer = defaultReplacer 1 tweak1
         where tweak1 bs1 = toByteString' $
                               if bs1 == toByteString' "左" then
                                     "ー右ー"
                                      else "?"
>>> runFn1 `shouldBe` toByteString "100メートルー右ー折後、左"
       where runFn1 =
                let rx1 = Pattern $ toByteString' "(?<=ル)(左)"
                    body1 = Body $ toByteString' "100メートル左折後、左"
                in replace (All rx1) replacer body1        
type H All = [MatchArray] Source 
type P All = [[PosLen]] Source 
type F All String = [[String]] Source 
type F All ByteString = [[ByteString]] Source 
type F All String = [[String]] Source 
type F All ByteString = [[ByteString]] Source 

newtype PosLen' a Source

Constructors

PosLen' a

once

Instances

Hint PosLen' Source 
MatchHint PosLen' String Source
>>> PosLen' ("и"::String) =~ "бывает и хуже"

[(13,2)]

MatchHint PosLen' ByteString Source 
MatchHint PosLen' Utf8_ String Source
>>> PosLen' ("и"::String) =~ "бывает и хуже"

[(13,2)]

MatchHint PosLen' Utf8_ ByteString Source 
type F PosLen' String = [PosLen] Source 
type F PosLen' ByteString = [PosLen] Source 
type F PosLen' String = [PosLen] Source 
type F PosLen' ByteString = [PosLen] Source 

class Hint hint where Source

Methods

unhint :: hint a -> a Source

hint :: a -> hint a Source