     
     public subscript(r: Range<Int>) -> String {
         let startIndex = self.characters.index(self.startIndex, offsetBy: max(0, r.lowerBound))
-        let endIndex = self.characters.index(self.startIndex, offsetBy: min(self.length, r.upperBound))
+        let endIndex = self.characters.index(self.startIndex, offsetBy: min(self.count, r.upperBound))
         return String(self[startIndex..<endIndex])
     }
     

    public func trim() -> String {
        return self.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
    }
}

    public func isMatch(_ regex: String, options: NSRegularExpression.Options) -> Bool {
        do {
            let exp = try NSRegularExpression(pattern: regex, options: options)
            return exp.numberOfMatches(in: self, options: [], range: NSMakeRange(0, self.count)) > 0
        } catch {
            return false
        }
