Moduleregex-pcre-builtin-0.95.2.3.8.44Haskell2010
Text.Regex.PCRE
The Text.Regex.PCRE module provides a backend for regular expressions. If you import this along with other backends, then you should do so with qualified imports, perhaps renamed for convenience.
Using the provided CompOption and ExecOption values and if configUTF8 is True, then you might be able to send UTF8 encoded ByteStrings to PCRE and get sensible results. This is currently untested.
The regular expression can be provided as a ByteString, but it will
be copied and a NUL byte appended to make a CString unless such a
byte is already present. Thus the regular expression cannot contain
an explicit NUL byte. The search string is passed as a CStringLen
and may contain NUL bytes and does not need to end in a NUL
byte. ByteStrings are searched in place (via unsafeUseAsCStringLen).
A String will be converted into a CString or CStringLen for
processing. Doing this repeatedly will be very inefficient.
The Text.Regex.PCRE.String, Text.Regex.PCRE.ByteString, and Text.Regex.PCRE.Wrap modules provides both the high level interface exported by this module and medium- and low-level interfaces that returns error using Either structures.
- 12 types
- 5 classes
- 29 values
- Packageregex-pcre-builtin-0.95.2.3.8.44
- Exports46
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourcePCRE.hs
RegexLike is parametrized on a regular expression type and a source type to run the matching on.
There are default implementations: matchTest and matchOnceText use matchOnce; matchCount and matchAllText use matchAll. Conversely, matchOnce uses matchOnceText and matchAll uses matchAllText. So a minimal complete instance need to provide at least (matchOnce or matchOnceText) and (matchAll or matchAllText). Additional definitions are often provided where they will increase efficiency.
[ c | let notVowel = makeRegex "[^aeiou]" :: Regex, c <- ['a'..'z'], matchTest notVowel [c] ]
"bcdfghjklmnpqrstvwxyz"The strictness of these functions is instance dependent.
Methods
matchOnce :: regex -> source -> Maybe MatchArrayThis returns the first match in the source (it checks the whole source, not just at the start). This returns an array of (offset,length) index pairs for the match and captured substrings. The offset is 0-based. A (-1) for an offset means a failure to match. The lower bound of the array is 0, and the 0th element is the (offset,length) for the whole match.
matchAll :: regex -> source -> [MatchArray]matchAllreturns a list of matches. The matches are in order and do not overlap. If any match succeeds but has 0 length then this will be the last match in the list.matchCount :: regex -> source -> IntmatchCountreturns the number of non-overlapping matches returned bymatchAll.matchTest :: regex -> source -> BoolmatchTestreturnsTrueif there is a match somewhere in the source (it checks the whole source not just at the start).matchAllText :: regex -> source -> [MatchText source]This is
matchAllwith the actual subsections of the source instead of just the (offset,length) information.matchOnceText :: regex -> source -> Maybe (source, MatchText source, source)This can return a tuple of three items: the source before the match, an array of the match and captured substrings (with their indices), and the source after the match.
Instances6RegexLike
RegexLike Regex ByteStringDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.ByteString · orphanRegexLike Regex ByteStringDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.ByteString.Lazy · orphanRegexLike Regex StringDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.String · orphanRegexLike Regex TextDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.Text · orphanRegexLike Regex TextDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.Text.Lazy · orphanRegexLike Regex (Seq Char)Defined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.Sequence · orphan
class RegexOptions regex compOpt execOpt | regex -> compOpt execOpt, compOpt -> regex execOpt, execOpt -> regex compOpt whereRather than carry them around separately, the options for how to
execute a regex are kept as part of the regex. There are two types
of options. Those that can only be specified at compilation time
and never changed are compOpt. Those that can be changed later and
affect how matching is performed are execOpt. The actually types
for these depend on the backend.
Methods
blankCompOpt :: compOptNo options set at all in the backend.
blankExecOpt :: execOptNo options set at all in the backend.
defaultCompOpt :: compOptReasonable options (extended, caseSensitive, multiline regex).
defaultExecOpt :: execOptReasonable options (extended, caseSensitive, multiline regex).
setExecOpts :: execOpt -> regex -> regexForget old flags and use new ones.
getExecOpts :: regex -> execOptRetrieve the current flags.
Instances1RegexOptions
RegexOptions Regex CompOption ExecOptionDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.Wrap
class RegexOptions regex compOpt execOpt => RegexMaker regex compOpt execOpt source | regex -> compOpt execOpt, compOpt -> regex execOpt, execOpt -> regex compOpt whereRegexMaker captures the creation of the compiled regular
expression from a source type and an option type. Methods makeRegexM and
makeRegexM report parse errors using MonadError, usually (Either
String regex).
The makeRegex function has a default implementation that depends on makeRegexOpts and uses defaultCompOpt and defaultExecOpt. Similarly for makeRegexM and makeRegexOptsM.
There are also default implementations for makeRegexOpts and makeRegexOptsM in terms of each other. So a minimal instance definition needs to only define one of these, hopefully makeRegexOptsM.
Methods
makeRegex :: source -> regexUse the defaultCompOpt and defaultExecOpt.
makeRegexOpts :: compOpt -> execOpt -> source -> regexSpecify your own options.
makeRegexM :: MonadFail m => source -> m regexUse the defaultCompOpt and defaultExecOpt, reporting errors with
fail.makeRegexOptsM :: MonadFail m => compOpt -> execOpt -> source -> m regexSpecify your own options, reporting errors with fail
Instances6RegexMaker
RegexMaker Regex CompOption ExecOption ByteStringDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.ByteString · orphanRegexMaker Regex CompOption ExecOption ByteStringDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.ByteString.Lazy · orphanRegexMaker Regex CompOption ExecOption StringDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.String · orphanRegexMaker Regex CompOption ExecOption TextDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.Text · orphanRegexMaker Regex CompOption ExecOption TextDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.Text.Lazy · orphanRegexMaker Regex CompOption ExecOption (Seq Char)Defined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.Sequence · orphan
RegexContext is the polymorphic interface to do matching. Since
target is polymorphic you may need to supply the type explicitly
in contexts where it cannot be inferred.
The monadic matchM version uses fail to report when the regex
has no match in source. Two examples:
Here the contest Bool is inferred:
[ c | let notVowel = makeRegex "[^aeiou]" :: Regex, c <- ['a'..'z'], match notVowel [c] ]
"bcdfghjklmnpqrstvwxyz"Here the context [String] must be supplied:
let notVowel = (makeRegex "[^aeiou]" :: Regex )
in do { c <- ['a'..'z'] ; matchM notVowel [c] } :: [String]
["b","c","d","f","g","h","j","k","l","m","n","p","q","r","s","t","v","w","x","y","z"]Instances32RegexContext, …
RegexContext Regex ByteString ByteStringDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.ByteString · orphanRegexContext Regex ByteString ByteStringDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.ByteString.Lazy · orphanRegexContext Regex String StringDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.String · orphanRegexContext Regex Text TextDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.Text · orphanRegexContext Regex Text TextDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.Text.Lazy · orphanRegexLike a b => RegexContext a b BoolDefined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b IntDefined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b MatchArrayDefined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b ()Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b (MatchResult b)Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b [MatchArray]Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b [MatchText b]Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b [[b]]Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b (AllMatches (Array Int) MatchArray)Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b (AllMatches (Array Int) (MatchOffset, MatchLength))Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b (AllMatches [] (MatchOffset, MatchLength))Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b (AllSubmatches [] (MatchOffset, MatchLength))Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b (AllTextMatches (Array Int) (Array Int b))Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b (AllTextMatches (Array Int) (MatchText b))Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b (AllTextMatches (Array Int) [b])Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b (AllTextMatches (Array Int) b)Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b (AllTextMatches [] (Array Int b))Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b (AllTextMatches [] b)Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b (AllTextSubmatches (Array Int) (b, (MatchOffset, MatchLength)))Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b (AllTextSubmatches (Array Int) b)Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b (AllTextSubmatches [] (b, (MatchOffset, MatchLength)))Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b (AllTextSubmatches [] b)Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b (MatchOffset, MatchLength)Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b (b, MatchText b, b)Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b (b, b, b)Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b (b, b, b, [b])Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexContext Regex (Seq Char) (Seq Char)Defined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.Sequence · orphan
0 based array, with 0th index indicating the full match. If the full match location is not available, represent as (0,0).
0 based index from start of source, or (-1) for unused
non-negative length of a match
Extract allows for indexing operations on String or ByteString.
Methods
before :: Int -> source -> sourcebeforeis a renamed take.after :: Int -> source -> sourceafteris a renamed drop.empty :: sourceWhen there is no match, this can construct an empty data value.
extract :: (Int, Int) -> source -> sourceextracttakes an offset and length, and has this default implementation:extract (off, len) source = before len (after off source)
Instances6Extract
Extract ByteStringDefined in regex-base-0.94.0.3 · Text.Regex.Base.RegexLikeExtract ByteStringDefined in regex-base-0.94.0.3 · Text.Regex.Base.RegexLikeExtract StringDefined in regex-base-0.94.0.3 · Text.Regex.Base.RegexLikeExtract TextDefined in regex-base-0.94.0.3 · Text.Regex.Base.RegexLikeExtract TextDefined in regex-base-0.94.0.3 · Text.Regex.Base.RegexLikeExtract (Seq a)Defined in regex-base-0.94.0.3 · Text.Regex.Base.RegexLike
Used in results of RegexContext instances.
Constructors
AllMatchesgetAllMatches :: f b
Instances3RegexContext
RegexLike a b => RegexContext a b (AllMatches (Array Int) MatchArray)Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b (AllMatches (Array Int) (MatchOffset, MatchLength))Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b (AllMatches [] (MatchOffset, MatchLength))Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphan
Used in results of RegexContext instances.
Constructors
Instances1RegexContext
RegexLike a b => RegexContext a b (AllSubmatches [] (MatchOffset, MatchLength))Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphan
Used in results of RegexContext instances.
Constructors
Instances6RegexContext
RegexLike a b => RegexContext a b (AllTextMatches (Array Int) (Array Int b))Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b (AllTextMatches (Array Int) (MatchText b))Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b (AllTextMatches (Array Int) [b])Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b (AllTextMatches (Array Int) b)Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b (AllTextMatches [] (Array Int b))Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b (AllTextMatches [] b)Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphan
Used in results of RegexContext instances.
Constructors
Instances4RegexContext
RegexLike a b => RegexContext a b (AllTextSubmatches (Array Int) (b, (MatchOffset, MatchLength)))Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b (AllTextSubmatches (Array Int) b)Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b (AllTextSubmatches [] (b, (MatchOffset, MatchLength)))Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphanRegexLike a b => RegexContext a b (AllTextSubmatches [] b)Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphan
This is the same as the type from JRegex.
Instances1RegexContext
RegexLike a b => RegexContext a b (MatchResult b)Defined in regex-base-0.94.0.3 · Text.Regex.Base.Context · orphan
A compiled regular expression
Instances19RegexOptions, RegexMaker, RegexLike, RegexContext, …
RegexLike Regex ByteStringDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.ByteString · orphanRegexLike Regex ByteStringDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.ByteString.Lazy · orphanRegexLike Regex StringDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.String · orphanRegexLike Regex TextDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.Text · orphanRegexLike Regex TextDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.Text.Lazy · orphanRegexContext Regex ByteString ByteStringDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.ByteString · orphanRegexContext Regex ByteString ByteStringDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.ByteString.Lazy · orphanRegexContext Regex String StringDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.String · orphanRegexContext Regex Text TextDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.Text · orphanRegexContext Regex Text TextDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.Text.Lazy · orphanRegexOptions Regex CompOption ExecOptionDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.WrapRegexMaker Regex CompOption ExecOption ByteStringDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.ByteString · orphanRegexMaker Regex CompOption ExecOption ByteStringDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.ByteString.Lazy · orphanRegexMaker Regex CompOption ExecOption StringDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.String · orphanRegexMaker Regex CompOption ExecOption TextDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.Text · orphanRegexMaker Regex CompOption ExecOption TextDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.Text.Lazy · orphanRegexMaker Regex CompOption ExecOption (Seq Char)Defined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.Sequence · orphanRegexLike Regex (Seq Char)Defined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.Sequence · orphanRegexContext Regex (Seq Char) (Seq Char)Defined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.Sequence · orphan
Constructors
Instances11Eq, Num, Show, Bits, RegexOptions, RegexMaker, …
Eq CompOptionDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.WrapNum CompOptionDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.WrapShow CompOptionDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.WrapBits CompOptionDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.WrapRegexOptions Regex CompOption ExecOptionDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.WrapRegexMaker Regex CompOption ExecOption ByteStringDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.ByteString · orphanRegexMaker Regex CompOption ExecOption ByteStringDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.ByteString.Lazy · orphanRegexMaker Regex CompOption ExecOption StringDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.String · orphanRegexMaker Regex CompOption ExecOption TextDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.Text · orphanRegexMaker Regex CompOption ExecOption TextDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.Text.Lazy · orphanRegexMaker Regex CompOption ExecOption (Seq Char)Defined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.Sequence · orphan
Constructors
Instances11Eq, Num, Show, Bits, RegexOptions, RegexMaker, …
Eq ExecOptionDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.WrapNum ExecOptionDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.WrapShow ExecOptionDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.WrapBits ExecOptionDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.WrapRegexOptions Regex CompOption ExecOptionDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.WrapRegexMaker Regex CompOption ExecOption ByteStringDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.ByteString · orphanRegexMaker Regex CompOption ExecOption ByteStringDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.ByteString.Lazy · orphanRegexMaker Regex CompOption ExecOption StringDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.String · orphanRegexMaker Regex CompOption ExecOption TextDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.Text · orphanRegexMaker Regex CompOption ExecOption TextDefined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.Text.Lazy · orphanRegexMaker Regex CompOption ExecOption (Seq Char)Defined in regex-pcre-builtin-0.95.2.3.8.44 · Text.Regex.PCRE.Sequence · orphan
Version string of PCRE library
NOTE: The Maybe type is used for historic reasons; practically, getVersion is never Nothing.