i have this text in which i need to extract only the digits on the first line
+1-415-655-0001 US TOLL
Access code: 197 703 792
the regex i have just extracts all digits
/d+
var noteStr = "1-415-655-0001 US TOLL\n\nAccess code: 197 703 792"
findCodeInWord()
func findCodeInWord() -> String?
{
let regex = try! NSRegularExpression(pattern: "\\d+", options: [])
var items = [String]()
regex.enumerateMatchesInString(noteStr, options: [], range: NSMakeRange(0, noteStr.characters.count)) { result, flag, stop in
guard let match = result else {
// result is nil
return
}
let range = match.rangeAtIndex(0)
var matchStr = (noteStr as NSString).substringWithRange(range)
print(matchStr)
}
return items.joinWithSeparator("")
}
but this returns all the digits. I only want it to return 14156550001