Created
June 17, 2016 12:11
-
-
Save tiaanduplessis/15508f414c93aced1321b2c0e9137e94 to your computer and use it in GitHub Desktop.
Matches for Regular Expression in text - Swift 2.2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func matchesForRegexInText(regex: String!, text: String!) -> [String] { | |
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)}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment