         let regex = NSRegularExpression(pattern: regexPattern, options: .CaseInsensitive, error: &error)
 
         // Run the expression and get matches
-        let length: Int = count(text)
-        if let matches = regex?.matchesInString(text, options: .ReportCompletion, range: NSMakeRange(0, length)) {
+        if let matches = regex?.matchesInString(text, options: .ReportCompletion, range: NSMakeRange(0, count(text.utf16))) {
 
             // Add all our ranges to the result
             for match in matches {
                 if let textCheckingResult = match as? NSTextCheckingResult {
                     let matchRange = textCheckingResult.range
-                    let stringIndexRange = advance(text.startIndex, matchRange.location)..<advance(text.startIndex, matchRange.location + matchRange.length)
-                    let matchString = text.substringWithRange(stringIndexRange)
+                    let stringIndexRange = text.rangeFromNSRange(matchRange)
+                    let matchString = text.substringWithRange(stringIndexRange!)
                     
-                    rangesForLinkType.append(LinkRangeResult(linkDetectionType: linkType, linkRange: stringIndexRange, linkString: matchString, textLink: nil))
+                    rangesForLinkType.append(LinkRangeResult(linkDetectionType: linkType, linkRange: stringIndexRange!, linkNSRange: matchRange, linkString: matchString, textLink: nil))
                 }
             }
         }

public class LinkRangeResult: NSObject {
    var linkDetectionType: ContextLabel.LinkDetectionType
    var linkRange: Range<String.Index>
    var linkString: String
    var textLink: ContextLabel.TextLink?
    
    // MARK: Initializers
    
    init(linkDetectionType: ContextLabel.LinkDetectionType, linkRange: Range<String.Index>, linkString: String, textLink: ContextLabel.TextLink?) {
        self.linkDetectionType = linkDetectionType
        self.linkRange = linkRange
        self.linkString = linkString
        self.textLink = textLink
        

    }
    
    private func getRangesForUserHandlesInText(text: String) -> [LinkRangeResult] {
        let rangesForUserHandles = getRangesForLinkType(LinkDetectionType.UserHandle, regexPattern: "(?<!\\w)@([\\w\\_.]+)?", text: text)
        return rangesForUserHandles
    }

