Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
struct Regex {
let pattern: String
let options: NSRegularExpressionOptions!
private var matcher: NSRegularExpression {
return NSRegularExpression(pattern: self.pattern, options: self.options, error: nil)
}
init(pattern: String, options: NSRegularExpressionOptions = nil) {
self.pattern = pattern
self.options = options
}
func match(string: String, options: NSMatchingOptions = nil) -> Bool {
return self.matcher.numberOfMatchesInString(string, options: options, range: NSMakeRange(0, string.utf16Count)) != 0
}
}
extension Regex: StringLiteralConvertible {
typealias ExtendedGraphemeClusterLiteralType = StringLiteralType
init(unicodeScalarLiteral value: UnicodeScalarLiteralType) {
self.pattern = "\(value)"
}
init(extendedGraphemeClusterLiteral value: ExtendedGraphemeClusterLiteralType) {
self.pattern = value
}
init(stringLiteral value: StringLiteralType) {
self.pattern = value
}
}
@MatrixSenpai

This comment has been minimized.

Copy link

MatrixSenpai commented Apr 24, 2016

Made redundant with the introduction of the following for Strings

String.rangeOfString(contains: String)

Use the following instead

extension String {
    func contains(find t: String) -> Bool {
       return self.rangeOfString(t) != nil
   }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.