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

        return nil
      }
      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)
      if let match = regex.firstMatch(in: string, options: options, range: range) {

      guard let regex = regex else {
        return (string, 0)
      }
      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
