Check if string contains special characters in Swift
问题 I have to detect whether a string contains any special characters. How can I check it? Does Swift support regular expressions? var characterSet:NSCharacterSet = NSCharacterSet(charactersInString: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLKMNOPQRSTUVWXYZ0123456789") if (searchTerm!.rangeOfCharacterFromSet(characterSet).location == NSNotFound){ println("Could not handle special characters") } I tried the code above, but it matches only if I enter the first character as a special character. 回答1: