How can I use NSRegularExpression on Swift strings with variable-width Unicode characters?
问题 I'm having trouble getting NSRegularExpression to match patterns on strings with wider (?) Unicode characters in them. It looks like the problem is the range parameter -- Swift counts individual Unicode characters, while Objective-C treats strings as if they're made up of UTF-16 code units. Here is my test string and two regular expressions: let str = "dog🐶🐮cow" let dogRegex = NSRegularExpression(pattern: "d.g", options: nil, error: nil)! let cowRegex = NSRegularExpression(pattern: "c.w",