find all the matches in the argument text; e.g., to count the number of naturals in s:
countMatches $ s *=~ [re|[0-9]+|]:: a typeCtrl KGHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27
Moduleregex-1.1.0.2Haskell2010
We have a regex tutorial at http://tutorial.regex.uk.
find all the matches in the argument text; e.g., to count the number of naturals in s:
countMatches $ s *=~ [re|[0-9]+|]find the first match in the argument text; e.g., to test if there is a natural number in the input text:
matched $ s ?=~ [re|[0-9]+|]search and replace all matches in the argument text; e.g., this section will convert every YYYY-MM-DD format date in its argument text into a DD/MM/YYYY date:
(*=~/ [ed|${y}([0-9]{4})-0*${m}([0-9]{2})-0*${d}([0-9]{2})///${d}/${m}/${y}|])search and replace the first occurrence only (if any) in the input text
e.g., to prefix the first string of four hex digits in the input text,
if any, with 0x:
(?=~/ [ed|[0-9A-Fa-f]{4}///0x$0|])the result of matching a RE against a text (with *=~), retaining
the text that was matched against
Functor MatchesDefined in regex-1.1.0.2 · Text.RE.ZeInternals.Types.Matches(RegexContext regex source [MatchText source], RegexLike regex source, RegexFix regex source) => RegexContext regex source (Matches source)Defined in regex-1.1.0.2 · Text.RE.ZeInternals.Types.Matchesthis instance hooks Matches into regex-base: regex consumers need not worry about any of this
Eq a => Eq (Matches a)Defined in regex-1.1.0.2 · Text.RE.ZeInternals.Types.MatchesShow a => Show (Matches a)Defined in regex-1.1.0.2 · Text.RE.ZeInternals.Types.Matchesthe source text being matched
all Match instances found, left to right
tests whether the RE matched the source text at all
count the matches
list the texts that Matched
the result of matching a RE to a text once (with ?=~), retaining
the text that was matched against
Functor MatchDefined in regex-1.1.0.2 · Text.RE.ZeInternals.Types.Match(RegexContext regex source (AllTextSubmatches (Array Int) (source, (Int, Int))), RegexLike regex source, RegexFix regex source) => RegexContext regex source (Match source)Defined in regex-1.1.0.2 · Text.RE.ZeInternals.Types.Matchthis instance hooks Match into regex-base: regex consumers need not worry about any of this
Eq a => Eq (Match a)Defined in regex-1.1.0.2 · Text.RE.ZeInternals.Types.MatchShow a => Show (Match a)Defined in regex-1.1.0.2 · Text.RE.ZeInternals.Types.Matchthe whole source text
tests whether the RE matched the source text at all
yields the text matched by the RE, Nothing if no match
There are a number of RE macros and corresponding Haskell parsers for parsing the matched text into appropriate Haskell types. See the Macros Tables for details.
module Text.RE.TestBench.Parsers
the RE type for this back end representing a well-formed, compiled RE
IsOption REOptionsDefined in regex-1.1.0.2 · Text.RE.ZeInternals.TDFAIsRegex RE ByteStringDefined in regex-1.1.0.2 · Text.RE.TDFA.ByteString · orphanIsRegex RE ByteStringDefined in regex-1.1.0.2 · Text.RE.TDFA.ByteString.Lazy · orphanIsRegex RE StringDefined in regex-1.1.0.2 · Text.RE.TDFA.String · orphanIsRegex RE TextDefined in regex-1.1.0.2 · Text.RE.TDFA.Text · orphanIsRegex RE TextDefined in regex-1.1.0.2 · Text.RE.TDFA.Text.Lazy · orphanIsRegex RE (Seq Char)Defined in regex-1.1.0.2 · Text.RE.TDFA.Sequence · orphanIsOption (Macros RE)Defined in regex-1.1.0.2 · Text.RE.ZeInternals.TDFAextract the RE source string from the RE
You can specify different compilation options by appending a to the name of an [re| ... |] or [ed| ... /// ... |] quasi quoter to select the corresponding compilation option. For example, the section,
(?=~/ [edBlockInsensitive|foo$///bar|])will replace a foo suffix of the argument text, of any
capitalisation, with a (lower case) bar. If you need to specify the
options dynamically, use the [re_| ... |] and [ed_| ... /// ... |]
quasi quoters, which generate functions that take an IsOption option
(e.g., a SimpleReOptions value) and yields a RE or SearchReplace
as appropriate. For example if you have a SimpleReOptions value in
sro then
(?=~/ [ed_|foo$///bar|] sro)will compile the foo$ RE according to the value of sro. For more
on specifying RE options see Text.RE.REOptions.
the default API uses these simple, universal RE options, which get auto-converted into the appropriate back-end REOptions_
MultilineSensitivecase-sensitive with ^ and $ matching the start and end of a line
MultilineInsensitivecase-insensitive with ^ and $ matsh the start and end of a line
BlockSensitivecase-sensitive with ^ and $ matching the start and end of the input text
BlockInsensitivecase-insensitive with ^ and $ matching the start and end of the input text
Bounded SimpleREOptionsDefined in regex-1.1.0.2 · Text.RE.REOptionsEnum SimpleREOptionsDefined in regex-1.1.0.2 · Text.RE.REOptionsEq SimpleREOptionsDefined in regex-1.1.0.2 · Text.RE.REOptionsOrd SimpleREOptionsDefined in regex-1.1.0.2 · Text.RE.REOptionsShow SimpleREOptionsDefined in regex-1.1.0.2 · Text.RE.REOptionsIsOption SimpleREOptionsDefined in regex-1.1.0.2 · Text.RE.ZeInternals.TDFALift SimpleREOptionsDefined in regex-1.1.0.2 · Text.RE.REOptionswe need to use this in the quasi quoters to specify SimpleREOptions
selected by the quasi quoter
contains a compiled RE and replacement template
SearchReplacegetSearch :: !rethe RE to match a string to replace
getTemplate :: !sthe replacement template with ${cap}
used to identify a capture (by number or
name if one was given) and $$ being
used to escape a single $
Functor (SearchReplace re)Defined in regex-1.1.0.2 · Text.RE.ZeInternals.Types.SearchReplace(Show re, Show s) => Show (SearchReplace re s)Defined in regex-1.1.0.2 · Text.RE.ZeInternals.Types.SearchReplacecompile a SearchReplace template generating errors if the RE or the template are not well formed, all capture references being checked
compile a SearchReplace template, with simple options, generating errors if the RE or the template are not well formed, all capture references being checked
convert a string into a RE that matches that string, and apply it to an argument continuation function to make up the RE string to be compiled; e.g., to compile a RE that will only match the string:
maybe undefined id . escape (("^"++) . (++"$"))a variant of escape where the SimpleREOptions are specified
Convert a string into a regular expression that will match that string
the `regex-base` polymorphic match operator
the `regex-base` monadic, polymorphic match operator
The [re|.*|] quasi quoters, with variants for specifying different
options to the RE compiler (see Text.RE.REOptions), and the
specialised back-end types and functions.
[re| ... |], is equivalent to [reMultilineSensitive| ... |],
compiling a case-sensitive, multi-line RE
[reMultilineSensitive| ... |], compiles a case-sensitive, multi-line RE
[reMultilineInsensitive| ... |], compiles a case-insensitive, multi-line RE
[reMultilineInsensitive| ... |], compiles a case-sensitive, non-multi-line RE
[reMultilineInsensitive| ... |], compiles a case-insensitive, non-multi-line RE
[reMS| ... |] is a shorthand for [reMultilineSensitive| ... |]
[reMI| ... |] is a shorthand for [reMultilineInsensitive| ... |]
[reBS| ... |] is a shorthand for [reBlockSensitive| ... |]
[reBI| ... |] is a shorthand for [reBlockInsensitive| ... |]
[re_| ... |] compiles a RE to produce a function that takes
the RE options (e.g., a SimpleREOptions value) and yields the
RE compiled with those options. For example,
countMatches $ s *=~ [re_|[0-9a-f]+|] MultilineInsensitivecounts the number of hexadecimal digit strings in s, allowing
for upper- or lower-case hex digits (which is entirely equivalent
in this example to just using [reMultilineInsensitive|[0-9a-f]+|]).
The [ed|.*///foo|] quasi quoters, with variants for specifying different
options to the RE compiler (see Text.RE.REOptions).
[edMultilineSensitive| ... /// ... |] compiles a case-sensitive, multi-line SearchReplace template
[edMultilineInsensitive| ... /// ... |] compiles a case-insensitive, multi-line SearchReplace template
[edBlockSensitive| ... /// ... |] compiles a case-sensitive, non-multi-line SearchReplace template
[edBlockInsensitive| ... /// ... |] compiles a case-insensitive, non-multi-line SearchReplace template
[ed| ... /// ... |], is equivalent to [edMultilineSensitive| ... /// ... |],
compiling a case-sensitive, multi-line SearchReplace
[edMS| ... /// ... |] is a shorthand for [edMultilineSensitive| ... /// ... |]
[edMI| ... /// ... |] is a shorthand for [edMultilineInsensitive| ... /// ... |]
[edBS| ... /// ... |] is a shorthand for [edBlockSensitive| ... /// ... |]
[edBI| ... /// ... |] is a shorthand for [edBlockInsensitive| ... /// ... |]
[ed_| ... /// ... |] compiles a SearchReplace template to produce a function that
takes the RE options (e.g., a SimpleREOptions value) and yields the
SearchReplace template compiled with those options. For example,
s *=~/ [ed_|${hex}([0-9a-f]+)///0x${hex}|] MultilineInsensitiveprefixes the hexadecimal digit strings in s with 0x, allowing for
upper- or lower-case hex digits (which is entirely equivalent
in this example to just using [edMultilineInsensitive|[0-9a-f]+|]).
quasi quoter for CaptureID: [cp|0|], [cp|0|], etc.,
indexing captures by classic positional numbers, and [cp|foo|],
etc., referencing a named capture [re| ... ${foo}( ... ) ... |].
The IsRegex class is used to abstract over the different regex back ends and the text types they work with -- see Text.RE.Tools.IsRegex for details.
module Text.RE.Tools.IsRegex