Skip to content

Instantly share code, notes, and snippets.

@dsharmaradicle
Created February 20, 2015 08:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsharmaradicle/e48a88fc3d153f5692ae to your computer and use it in GitHub Desktop.
Save dsharmaradicle/e48a88fc3d153f5692ae to your computer and use it in GitHub Desktop.
Might be this will helpful to remove error:
func isMatch(regex: String, options: NSRegularExpressionOptions) -> Bool
{
var error: NSError?
var exp = NSRegularExpression(pattern: regex, options: options, error: &error)
if let error = error {
println(error.description)
}
var matchCount = exp?.numberOfMatchesInString(self, options: nil, range: NSMakeRange(0, self.length))
return matchCount > 0
}
func getMatches(regex: String, options: NSRegularExpressionOptions) -> [NSTextCheckingResult]
{
var error: NSError?
var exp = NSRegularExpression(pattern: regex, options: options, error: &error)
if let error = error {
println(error.description)
}
var matches = exp?.matchesInString(self, options: nil, range: NSMakeRange(0, self.length))
return matches as [NSTextCheckingResult]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment