             // Add a range entry for every url we found
             for match in matches {
                 let matchRange = match.range
-                let stringIndexRange = text.startIndex.advancedBy(matchRange.location)..<text.startIndex.advancedBy(matchRange.location + matchRange.length)
                 
                 // If there's a link embedded in the attributes, use that instead of the raw text
                 var realURL: AnyObject? = attributedString.attribute(NSLinkAttributeName, atIndex: matchRange.location, effectiveRange: nil)
                 if realURL == nil {
-                    let range = text.startIndex.advancedBy(matchRange.location)..<text.startIndex.advancedBy(matchRange.location + matchRange.length)
-                    realURL = plainText.substringWithRange(range)
+                    realURL = NSString(string: plainText).substringWithRange(matchRange)
                 }
                 
                 if match.resultType == .Link {
                     if let matchString = realURL as? String {
-                        rangesForURLs.append(LinkRangeResult(linkDetectionType: LinkDetectionType.URL, linkRange: stringIndexRange, linkString: matchString, textLink: nil))
+                        rangesForURLs.append(LinkRangeResult(linkDetectionType: LinkDetectionType.URL, linkRange: matchRange, linkString: matchString, textLink: nil))
                     }
                 }
             }

            // Add all our ranges to the result
            for match in matches {
                let matchRange = match.range
                let stringIndexRange = text.startIndex.advancedBy(matchRange.location)..<text.startIndex.advancedBy(matchRange.location + matchRange.length)
                let matchString = text.substringWithRange(stringIndexRange)
                
                rangesForLinkType.append(LinkRangeResult(linkDetectionType: linkType, linkRange: stringIndexRange, linkString: matchString, textLink: nil))
            }
        }



        if let linkRangeResult = getLinkRangeResultWithTouches(touches) {
            
            if linkRangeResult.linkRange.location != selectedLinkRangeResult?.linkRange.location  {
                if let selectedLinkRangeResult = selectedLinkRangeResult, attributedText = attributedText {
                    self.attributedText = addLinkAttributesToAttributedString(attributedText, withLinkRangeResults: [selectedLinkRangeResult], highlighted: false)
                }
