replacing(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>(maxReplacements: Int = .max, @RegexComponentBuilder content: () -> some RegexComponent, with replacement: (Regex<Output>.Match) throws -> Replacement) rethrows -> Self where Replacement : Collection, Replacement.Element == CharacterParameters
- maxReplacements:
A number specifying how many occurrences of the regex to replace, using
contentto create the regex. - 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.