replacing(_:with:subrange:maxReplacements:)
Returns a new collection in which all occurrences of a sequence matching the given regex are replaced by another collection.
Declaration
func replacing<Replacement>(_ regex: some RegexComponent, with replacement: Replacement, subrange: Range<Self.Index>, maxReplacements: Int = .max) -> Self where Replacement : Collection, Replacement.Element == CharacterParameters
- regex:
A regex describing the sequence to replace.
- replacement:
The new elements to add to the collection.
- subrange:
The range in the collection in which to search for
regex. - maxReplacements:
A number specifying how many occurrences of the sequence matching
regexto replace. Default isInt.max.
Return Value
A new collection in which all occurrences of subsequence matching regex in subrange are replaced by replacement.