replacing(subrange:maxReplacements:content:with:)
Returns a new collection in which all matches for the regex are replaced, using the given closures to create the replacement and the regex.
Declaration
func replacing<Output, Replacement>(subrange: Range<Self.Index>, maxReplacements: Int = .max, @RegexComponentBuilder content: () -> some RegexComponent, with replacement: (Regex<Output>.Match) throws -> Replacement) rethrows -> Self where Replacement : Collection, Replacement.Element == CharacterParameters
- subrange:
The range in the collection in which to search for the regex, using
contentto create the regex. - maxReplacements:
A number specifying how many occurrences of the regex to replace.
- content:
A closure that returns the collection to search for and replace.
- replacement:
A closure that receives the full match information, including captures, and returns a replacement collection.
Return Value
A new collection in which all matches for regex in subrange are replaced by the result of calling replacement, where regex is the result of calling content.