 
 
 
-private extension String {
-    
-    subscript(range: NSRange) -> SubSequence {
-        
-        return self[Range(range, in: self)!]
+private extension NSTextCheckingResult {
+    
+    func double(in string: String, at index: Int) -> Double? {
+        
+        let range = Range(self.range(at: index), in: string)!
+        
+        return Double(string[range])
     }
     
 }

            
        case .cssRGB:
            guard
                let r = Double(code[result.range(at: 1)]),
                let g = Double(code[result.range(at: 2)]),
                let b = Double(code[result.range(at: 3)])
            else { return nil }
            self = .rgb(r / 255, g / 255, b / 255)
            
        case .cssRGBa:
            guard
                let r = Double(code[result.range(at: 1)]),
                let g = Double(code[result.range(at: 2)]),
                let b = Double(code[result.range(at: 3)]),
                let a = Double(code[result.range(at: 4)])
            else { return nil }
            self = .rgb(r / 255, g / 255, b / 255, alpha: a)
            
        case .cssHSL:
            guard
                let h = Double(code[result.range(at: 1)]),
                let s = Double(code[result.range(at: 2)]),
                let l = Double(code[result.range(at: 3)])
            else { return nil }
            self = .hsl(h / 360, s / 100, l / 100)
            
        case .cssHSLa:
            guard
                let h = Double(code[result.range(at: 1)]),
                let s = Double(code[result.range(at: 2)]),
                let l = Double(code[result.range(at: 3)]),
                let a = Double(code[result.range(at: 4)])
            else { return nil }
            self = .hsl(h / 360, s / 100, l / 100, alpha: a)
            
        case .cssKeyword:
            let lowercase = code.lowercased()
            guard
                let hex = colorKeywordMap.first(where: { $0.key.lowercased() == lowercase })?.value
            else { return nil }
            self.init(hex: hex)
        }
        

        type = nil
        
        let code = colorCode.trimmingCharacters(in: .whitespacesAndNewlines)
        
        // detect code type
        guard let (detectedType, result) = ColorCodeType.allCases.lazy
