Created
May 9, 2016 20:47
-
-
Save algal/8225f9d70f4a725d25a758357de3b628 to your computer and use it in GitHub Desktop.
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
// known-good: Swift 2.2, Xcode 7.3 | |
struct Regex { | |
let matcher:NSRegularExpression | |
init?(pattern: String, options: NSRegularExpressionOptions = []) { | |
guard let m = try? NSRegularExpression(pattern: pattern, options: options) else { return nil } | |
self.matcher = m | |
} | |
func match(string: String, options: NSMatchingOptions = []) -> Bool { | |
let stringRange = NSMakeRange(0, (string as NSString).length) | |
let matches = self.matcher.numberOfMatchesInString(string, | |
options: options, | |
range: stringRange) | |
return matches != 0 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment