在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
在playground内写入以下代码,正则关键字跟其它语言的没什么区别 class Regex { let internalExpression:NSRegularExpression let pattern:String init(pattern:String) { self.pattern = pattern var error:NSError? self.internalExpression = NSRegularExpression(pattern: pattern, options: NSRegularExpressionOptions.CaseInsensitive, error: &error)! } func match(input:String) -> Bool { let matches = self.internalExpression.matchesInString(input, options: nil, range: NSMakeRange(0, count(input))) return matches.count > 0 } } var email_regex = case Email = "^([a-zA-Z0-9]+([._\\-])*[a-zA-Z0-9]*)+@([a-zA-Z0-9])+(.([a-zA-Z])+)+$" var regex = Regex(pattern:email_regex) regex.match("[email protected]") //RETURN true CaseInsensitive:大小写不敏感 |
请发表评论