regex-0.10.0.3: Toolkit for regex-base

Copyright(C) 2016-17 Chris Dornan
LicenseBSD3 (see the LICENSE file)
MaintainerChris Dornan <chris.dornan@irisconnect.com>
StabilityRFC
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Text.RE

Contents

Description

 

Synopsis

The Tutorial

We have a regex tutorial at http://tutorial.regex.uk.

How to use this library

This module just provides an overview of the key type on which the regex package is built. You will need to import one of the API modules of which there is a choice which will depend upon two factors:

  • Which flavour of regular expression do you want to use? If you want Posix flavour REs then you want the TDFA modules, otherwise its PCRE for Perl-style REs.
  • What type of text do you want to match: (slow) Strings, ByteString, ByteString.Lazy, Text, Text.Lazy or the anachronistic Seq Char or indeed a good old-fashioned polymorphic operators?

While we aim to provide all combinations of these choices, some of them are currently not available. In the regex package we have:

The PCRE modules are contained in the separate regex-with-pcre package:

  • Text.RE.PCRE.ByteString
  • Text.RE.PCRE.ByteString.Lazy
  • Text.RE.PCRE.RE
  • Text.RE.PCRE.Sequence
  • Text.RE.PCRE.String
  • Text.RE.PCRE

Matches

data Matches a Source #

the result type to use when every match is needed, not just the first match of the RE against the source

Instances

Functor Matches Source # 

Methods

fmap :: (a -> b) -> Matches a -> Matches b #

(<$) :: a -> Matches b -> Matches a #

(RegexContext regex source [MatchText source], RegexLike regex source) => RegexContext regex source (Matches source) Source #

this instance hooks Matches into regex-base: regex consumers need not worry about any of this

Methods

match :: regex -> source -> Matches source #

matchM :: Monad m => regex -> source -> m (Matches source) #

Eq a => Eq (Matches a) Source # 

Methods

(==) :: Matches a -> Matches a -> Bool #

(/=) :: Matches a -> Matches a -> Bool #

Show a => Show (Matches a) Source # 

Methods

showsPrec :: Int -> Matches a -> ShowS #

show :: Matches a -> String #

showList :: [Matches a] -> ShowS #

matchesSource :: Matches a -> a Source #

the source text being matched

allMatches :: Matches a -> [Match a] Source #

all Match instances found, left to right

anyMatches :: Matches a -> Bool Source #

tests whether the RE matched the source text at all

countMatches :: Matches a -> Int Source #

count the matches

matches :: Matches a -> [a] Source #

list the Matches

Match

data Match a Source #

the result of matching a RE to a text once, listing the text that was matched and the named captures in the RE and all of the substrings matched, with the text captured by the whole RE; a complete failure to match will be represented with an empty array (with bounds (0,-1))

Instances

Functor Match Source # 

Methods

fmap :: (a -> b) -> Match a -> Match b #

(<$) :: a -> Match b -> Match a #

(RegexContext regex source (AllTextSubmatches (Array Int) (source, (Int, Int))), RegexLike regex source) => RegexContext regex source (Match source) Source #

this instance hooks Match into regex-base: regex consumers need not worry about any of this

Methods

match :: regex -> source -> Match source #

matchM :: Monad m => regex -> source -> m (Match source) #

Eq a => Eq (Match a) Source # 

Methods

(==) :: Match a -> Match a -> Bool #

(/=) :: Match a -> Match a -> Bool #

Show a => Show (Match a) Source # 

Methods

showsPrec :: Int -> Match a -> ShowS #

show :: Match a -> String #

showList :: [Match a] -> ShowS #

matchSource :: Match a -> a Source #

the whole source text

matched :: Match a -> Bool Source #

tests whether the RE matched the source text at all

matchedText :: Match a -> Maybe a Source #

tests whether the RE matched the source text at all