 
             :returns: Subscript for the capture group.
         */
-        public subscript(index: Int) -> String {
-            return subject[ranges[index]]
+        public subscript(index: Int) -> String? {
+            if let range = ranges[index] {
+                return subject[range]
+            } else {
+                return nil
+            }
         }
     }
 

        return search(subject) != nil
    }
}


        /** The string that was matched. */
        public let subject: String
        /** Ranges of the matches, with the entire pattern match in 0. */
        public let ranges: [Range<String.Index>?]
        /** Count of the capture groups, including the entire pattern match. */
        public var count: Int { return ranges.count }

        init(subject: String, matchResult: NSTextCheckingResult) {
            self.subject = subject

            var ranges: [Range<String.Index>?] = []

            // Check the overall match first. Shouldn't happen
            if matchResult.range.location == NSNotFound {
