RosettaCodeData/Task/Regular-expressions/Swift/regular-expressions-4.swift
2016-12-05 23:44:36 +01:00

5 lines
299 B
Swift

for x in regex.matchesInString(str, options: nil, range: NSRange(location: 0, length: count(str.utf16))) {
let match = x as! NSTextCheckingResult
// match.range gives the range of the whole match
// match.rangeAtIndex(i) gives the range of the i'th capture group (starting from 1)
}