Created
December 29, 2016 12:11
-
-
Save chriswebb09/fad6b09a1a7229a6a59a93c646eae05a to your computer and use it in GitHub Desktop.
Regex
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
import Foundation | |
struct Regex { | |
let pattern: String | |
let options: NSRegularExpression.Options! | |
private var matcher: NSRegularExpression { | |
let matcher = try? NSRegularExpression(pattern: self.pattern) | |
return matcher! | |
} | |
init(pattern: String, options: NSRegularExpression.Options? = nil) { | |
self.pattern = pattern | |
self.options = options | |
} | |
func match(string: String, options: NSRegularExpression.MatchingOptions) -> Bool { | |
return matcher.numberOfMatches(in: string, options: options, range: NSMakeRange(0, string.utf16.count)) != 0 | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment