HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

  • Packageregex-1.1.0.2
  • Exports45
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceReplace.lhs

The Replacing Tutorial

0 declarations

This API module covers the specialised regex tools for doing general editing on text, including the internal details of the Matches and Match types and the associated functions for extracting captures and applying functions to them to transform the subject text.

See the tutorials at http://re-tutorial-replacing.regex.uk

replaceAll

4 declarations
valuereplaceAll :: Replace a => a -> Matches a -> a
#

replace all with a template, $0 for whole text, $1 for first capture, etc.

replace

4 declarations

REContext and RELocation

3 declarations
datadata REContext
#

REContext specifies which contexts the substitutions should be applied

Constructors

  • TOP

    substitutions should be applied to the top-level only, the text that matched the whole RE

  • SUB

    substitutions should only be applied to the text captured by bracketed sub-REs

  • ALL

    the substitution function should be applied to all captures, the top level and the sub-expression captures

Instances1Show
  • Show REContextDefined in regex-1.1.0.2 · Text.RE.ZeInternals.Replace
datadata RELocation
#

the RELocation information passed into the substitution function specifies which sub-expression is being substituted

Constructors

  • RELocation
    • locationMatch :: Int

      the zero-based, i-th string to be matched, when matching all strings, zero when only the first string is being matched

    • locationCapture :: CaptureOrdinal

      0, when matching the top-level string matched by the whole RE, 1 for the top-most, left-most redex captured by bracketed sub-REs, etc.

Instances1Show
  • Show RELocationDefined in regex-1.1.0.2 · Text.RE.ZeInternals.Replace

Matches

5 declarations
datadata Matches a
#

the result of matching a RE against a text (with *=~), retaining the text that was matched against

Constructors

Instances4Functor, RegexContext, Eq, Show
  • 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.Matches

    this 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.Matches
  • Show a => Show (Matches a)Defined in regex-1.1.0.2 · Text.RE.ZeInternals.Types.Matches

Match

16 declarations
datadata Match a
#

the result of matching a RE to a text once (with ?=~), retaining the text that was matched against

Constructors

Instances4Functor, RegexContext, Eq, Show
  • 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.Match

    this 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.Match
  • Show a => Show (Match a)Defined in regex-1.1.0.2 · Text.RE.ZeInternals.Types.Match
valuenoMatch :: a -> Match a
#

Construct a Match that does not match anything.

valuematched :: Match a -> Bool
#

tests whether the RE matched the source text at all

valuecaptureText :: CaptureID -> Match a -> a
#

look up the text of the nth capture, 0 being the match of the whole RE against the source text, 1, the first bracketed sub-expression to be matched and so on

valuecaptureTextMaybe :: CaptureID -> Match a -> Maybe a
#

look up the text of the nth capture (0 being the match of the whole), returning Nothing if the Match doesn't contain the capture

valuecapture :: CaptureID -> Match a -> Capture a
#

look up the nth capture, 0 being the match of the whole RE against the source text, 1, the first bracketed sub-expression to be matched and so on

valuecaptureMaybe :: CaptureID -> Match a -> Maybe (Capture a)
#

look up the nth capture, 0 being the match of the whole RE against the source text, 1, the first bracketed sub-expression to be matched and so on, returning Nothing if there is no such capture, or if the capture failed to capture anything (being in a failed alternate)

valueconvertMatchText
  1. :: RegexFix regex source
  2. => regex
  3. -> source
  4. -> MatchText source
  5. -> Match source
#

convert a regex-base native MatchText into a regex Match type

Capture

4 declarations
datadata Capture a
#

the matching of a single sub-expression against part of the source text

Constructors

Instances3Functor, Eq, Show
  • Functor CaptureDefined in regex-1.1.0.2 · Text.RE.ZeInternals.Types.Capture
  • Eq a => Eq (Capture a)Defined in regex-1.1.0.2 · Text.RE.ZeInternals.Types.Capture
  • Show a => Show (Capture a)Defined in regex-1.1.0.2 · Text.RE.ZeInternals.Types.Capture

CaptureID

6 declarations
newtypenewtype CaptureOrdinal
#

a CaptureOrdinal is just the number of the capture, starting with 0 for the whole of the text matched, then in leftmost, outermost

Instances6Enum, Eq, Num, Ord, Show, Ix

Replace and ReplaceMethods

3 declarations
classclass (Show a, Eq a, Ord a, Extract a, Monoid a) => Replace a where
#

Replace provides the missing needed to replace the matched text in a Replace a => Match a.

Methods

Instances6Replace
  • Replace ByteStringDefined in regex-1.1.0.2 · Text.RE.ZeInternals.Replace
  • Replace ByteStringDefined in regex-1.1.0.2 · Text.RE.ZeInternals.Replace
  • Replace TextDefined in regex-1.1.0.2 · Text.RE.ZeInternals.Replace
  • Replace TextDefined in regex-1.1.0.2 · Text.RE.ZeInternals.Replace
  • Replace (Seq Char)Defined in regex-1.1.0.2 · Text.RE.ZeInternals.Replace
  • Replace [Char]Defined in regex-1.1.0.2 · Text.RE.ZeInternals.Replace