      - throws: An error if pattern is invalid.
      */
     public mutating func setPattern(_ pattern: String) throws {
-        regularExpression = try NSRegularExpression(pattern: pattern, options: regularExpression.options)
+        self = try Regex(pattern: pattern, options: self.options)
     }
     
     

            return regularExpression.options
        }
        set {
            regularExpression = try! NSRegularExpression(pattern: regularExpression.pattern, options: newValue)
        }
    }
    
    
    /// The number of capture groups.
    public var numberOfCaptureGroups: Int { return regularExpression.numberOfCaptureGroups }
    
}


    
    /// Wrapped NSRegularExpression.
    public var regularExpression: NSRegularExpression
    
    
    
    /**
     Creates a `Regex` with unchecked string literal and options. Runtime error is raised if the unchecked pattern is invalid.
