I use a code from Swift extract regex matches
func matchesForRegexInText(regex: String!, text: String!) -> [String] {
do {
let regex = try NSRegularExpression(pattern: regex, options: [])
let nsString = text as NSString
let results = regex.matchesInString(text,
options: [], range: NSMakeRange(0, nsString.length))
return results.map { nsString.substringWithRange($0.range)}
} catch let error as NSError {
print("invalid regex: \(error.localizedDescription)")
return []
}
}
I try match this pattern (sample pattern) "^([a-z]+).*?(\d+)$"
And if I use it for string "abc.....123" I get as result this full string...
But I want to get array of strings ["abc", "123"]