replace all with a template, $0 for whole text, $1 for first capture, etc.
Moduleregex-1.1.0.2Haskell2010
Text.RE.Replace
- 10 types
- 1 class
- 34 values
- Packageregex-1.1.0.2
- Exports45
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceReplace.lhs
The Replacing Tutorial
0 declarationsThis 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 declarationssubstitutes using a function that takes the full Match context and returns the same replacement text as the _phi_phi context.
replaceAllCaptures_ is like like replaceAllCaptures but takes the Replace methods through the ReplaceMethods argument
replaceAllCapturesM is just a monadically generalised version of replaceAllCaptures_
replace
4 declarationssubstitutes using a function that takes the full Match context and returns the same replacement text as the _phi_phi context.
replaceCaptures_ is like replaceCaptures but takes the Replace methods through the ReplaceMethods argument
replaceCapturesM is just a monadically generalised version of replaceCaptures_
REContext and RELocation
3 declarationsREContext specifies which contexts the substitutions should be applied
the RELocation information passed into the substitution function
specifies which sub-expression is being substituted
Constructors
RELocationlocationMatch :: Intthe zero-based, i-th string to be matched, when matching all strings, zero when only the first string is being matched
locationCapture :: CaptureOrdinal0, 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
True iff the location references a complete match (i.e., not a bracketed capture)
Matches
5 declarationsthe result of matching a RE against a text (with *=~), retaining
the text that was matched against
Constructors
MatchesmatchesSource :: !athe source text being matched
allMatches :: ![Match a]all Match instances found, left to right
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.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.Matches
tests whether the RE matched the source text at all
count the matches
list the texts that Matched
extract the main capture from each match
Match
16 declarationsthe result of matching a RE to a text once (with ?=~), retaining
the text that was matched against
Constructors
MatchmatchSource :: !athe whole source text
captureNames :: !CaptureNamesthe RE's capture names
matchArray :: !Array CaptureOrdinal (Capture a).n-1 captures, starting with the text matched by the whole RE
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.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.Match
Construct a Match that does not match anything.
an empty array of Capture
tests whether the RE matched the source text at all
yields the text matched by the RE, Nothing if no match
the top-level capture if the source text matched the RE, Nothing otherwise
the main top-level capture (capture '0'') and the sub captures
if the text matched the RE, Nothing otherwise
an alternative for captureText
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
an alternative for captureTextMaybe
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
an alternative for capture
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
an alternative for capture captureMaybe
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)
convert a regex-base native MatchText into a regex Match type
Capture
4 declarationsthe matching of a single sub-expression against part of the source text
Constructors
CapturecaptureSource :: !athe whole text that was searched
capturedText :: !athe text that was matched
captureOffset :: !Intthe number of characters preceding the match with -1 used if no text was captured by the RE (not even the empty string)
captureLength :: !Intthe number of chacter in the captured sub-string
test if the capture has matched any text
returns the text preceding the match
returns the text after the match
CaptureID
6 declarationsCaptureID identifies captures, either by number (e.g., [cp|1|]) or name (e.g., [cp|foo|]).
Constructors
the dictionary for named captures stored in compiled regular expressions associates
an empty CaptureNames dictionary
a CaptureName is just the text of the name
Constructors
Instances4Eq, Ord, Show, Hashable
Eq CaptureNameDefined in regex-1.1.0.2 · Text.RE.ZeInternals.Types.CaptureIDOrd CaptureNameDefined in regex-1.1.0.2 · Text.RE.ZeInternals.Types.CaptureIDShow CaptureNameDefined in regex-1.1.0.2 · Text.RE.ZeInternals.Types.CaptureIDHashable CaptureNameDefined in regex-1.1.0.2 · Text.RE.ZeInternals.Types.CaptureID
a CaptureOrdinal is just the number of the capture, starting with 0 for the whole of the text matched, then in leftmost, outermost
Constructors
Instances6Enum, Eq, Num, Ord, Show, Ix
Enum CaptureOrdinalDefined in regex-1.1.0.2 · Text.RE.ZeInternals.Types.CaptureIDEq CaptureOrdinalDefined in regex-1.1.0.2 · Text.RE.ZeInternals.Types.CaptureIDNum CaptureOrdinalDefined in regex-1.1.0.2 · Text.RE.ZeInternals.Types.CaptureIDOrd CaptureOrdinalDefined in regex-1.1.0.2 · Text.RE.ZeInternals.Types.CaptureIDShow CaptureOrdinalDefined in regex-1.1.0.2 · Text.RE.ZeInternals.Types.CaptureIDIx CaptureOrdinalDefined in regex-1.1.0.2 · Text.RE.ZeInternals.Types.CaptureID
look up a CaptureID in the CaptureNames dictionary
Replace and ReplaceMethods
3 declarationsReplace provides the missing needed to replace the matched
text in a Replace a => Match a.
Methods
lengthR :: a -> Intlength function for a
packR :: String -> ainject String into a
unpackR :: a -> Stringproject a onto a String
textifyR :: a -> Textinject into Text
detextifyR :: Text -> aproject Text onto a
linesR :: a -> [a]split into lines
unlinesR :: [a] -> aconcatenate a list of lines
appendNewlineR :: a -> aappend a newline
substR :: (a -> a) -> Capture a -> aapply a substitution function to a Capture
parseTemplateR :: a -> Match a -> RELocation -> Capture a -> Maybe aconvert a template containing $0, $1, etc., in the first argument, into a
phireplacement function for use with replaceAllCaptures and replaceCaptures
Instances6Replace
Replace ByteStringDefined in regex-1.1.0.2 · Text.RE.ZeInternals.ReplaceReplace ByteStringDefined in regex-1.1.0.2 · Text.RE.ZeInternals.ReplaceReplace TextDefined in regex-1.1.0.2 · Text.RE.ZeInternals.ReplaceReplace TextDefined in regex-1.1.0.2 · Text.RE.ZeInternals.ReplaceReplace (Seq Char)Defined in regex-1.1.0.2 · Text.RE.ZeInternals.ReplaceReplace [Char]Defined in regex-1.1.0.2 · Text.RE.ZeInternals.Replace
a selection of the Replace methods can be encapsulated with ReplaceMethods for the higher-order replacement functions
Constructors
ReplaceMethodsmethodLength :: a -> IntmethodSubst :: (a -> a) -> Capture a -> a
replaceMethods encapsulates ReplaceMethods a from a Replace a context