lowerBoundand upperBoundare immutable range properties, so you need to create a new range starting at match.upperBound.
Also, the loop should end if no match is found. This can be achieved by moving the binding
let match = ...to the where clause.
var range = self.startIndex..<self.endIndex
while range.lowerBound < range.upperBound,
let match = self.range(of: regex, options: .regularExpression, range: range) {
print(match)
print(self.substring(with: match))
range = match.upperBound..<self.endIndex
}
,
(, regex = "^"). ,
NSRegularExpression,
(., , Swift extract regex).