       guard let regex = regex else {
         return (string, 0)
       }
-      let range = NSRange(location: 0, length: string.characters.count)
+      let range = NSRange(location: 0, length: string.utf16.count)
       let mutable = NSMutableString(string: string)
       let maxCount = count == 0 ? Int.max : (count > 0 ? count : 0)
       var n = 0

        return []
      }
      let start = pos > 0 ?pos :0
      let end = endpos ?? string.characters.count
      let length = max(0, end - start)
      let range = NSRange(location: start, length: length)
      return regex.matchesInString(string, options: [], range: range).map { MatchObject(string: string, match: $0) }

        return nil
      }
      let start = pos > 0 ?pos :0
      let end = endpos ?? string.utf16.count
      let length = max(0, end - start)
      let range = NSRange(location: start, length: length)
      if let match = regex.firstMatchInString(string, options: options, range: range) {
