Skip to content

Instantly share code, notes, and snippets.

@tiaanduplessis
Created June 17, 2016 12:11
Show Gist options
  • Save tiaanduplessis/15508f414c93aced1321b2c0e9137e94 to your computer and use it in GitHub Desktop.
Save tiaanduplessis/15508f414c93aced1321b2c0e9137e94 to your computer and use it in GitHub Desktop.
Matches for Regular Expression in text - Swift 2.2
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