struct regexhelper { let regex: nsregularexpression? init (_ pattern: string) { var error: NSError? regex = Nsregularexpression (pattern: pattern, options: . caseinsensitive, error: &error) } func match (input: string) -> Bool { if let matches = regex?. MatchesinstrinG (input, options: nil, range: nsmakerange (0, count (input)) { return matches.count > 0 } else { return false } } } //authentication method let mailpattern = "^ ([a-z0-9_\\.-]+) @ ([\\da-z\\.-]+)\\. ([a-z\\.] {2,6}) $ " let matcher = regexhelper (MailPattern) let maybemailaddress = "[email protected]" if matcher.match (maybemailaddress) {             PRINTLN ("Valid e-mail address") } else     {        PRINTLN ("Invalid email address") }
Examples of Swift regular expressions (selected from "Swifter 100 swift Development Essentials Tip")