         let nsstring = NSString(string: self)
         let range = NSRange(location: 0, length: nsstring.length)
         var match_result = [String]()
-        regex.matcher.enumerateMatches(in: self, options: [], range: range) { result, _, _ in
+        regex.regex.enumerateMatches(in: self, options: [], range: range) { result, _, _ in
             if let _result = result {
                 match_result.append(nsstring.substring(with: _result.range))
             }

//  THE SOFTWARE.
//

public struct Regex: Equatable {
    
    fileprivate let matcher: NSRegularExpression
    
    public init(pattern: String) throws {
        self.matcher = try NSRegularExpression(pattern: pattern, options: [])
    }
    
    public init(pattern: String, options: NSRegularExpression.Options) throws {
        self.matcher = try NSRegularExpression(pattern: pattern, options: options)
    }
    
    /// Returns the regular expression pattern.
    public var pattern: String {
        return matcher.pattern
    }
    
    /// Returns the options used when the regular expression option was created.
    public var options: NSRegularExpression.Options {
        return matcher.options
    }
    
    /// Returns the number of capture groups in the regular expression.
    ///
    /// A capture group consists of each possible match within a regular expression. Each capture group can then be used in a replacement template to insert that value into a replacement string.
    public var numberOfCaptureGroups: Int {
        return matcher.numberOfCaptureGroups
    }
}


    public func replace(regex: Regex, template: String) -> String {
        let nsstring = NSString(string: self)
        let range = NSRange(location: 0, length: nsstring.length)
        return regex.regex.stringByReplacingMatches(in: self, options: [], range: range, withTemplate: template)
    }
}

