Post

Replies

Boosts

Views

Activity

How to capture unknown number of matches using RegexBuilder?
I know how to match unknown number of fields with using 'range' and '.regularExpression' option as shown below, but how do i do it with the new RegexBuilder or multi-line literal? func matches(for regex: String, in text: String) -> [String] { var result = [String]() var startIndex = text.startIndex let endIndex = text.endIndex while let range = text.range(of: regex, options: .regularExpression, range: startIndex ..< endIndex) { result.append(String(text[range])) startIndex = range.upperBound } return result }
1
0
502
Jul ’23