Swift3 如何 字符串中 过滤emoji表情

http://stackoverflow.com/questions/38408645/swift-regex-to-match-unicodes

The Unicode code point of the emoji you have shown is U+1F600.

(Unicode 9.0 Character Code Charts – Emoticons)

And your regex pattern (which may work for UTF-16 representation) [\uD800-\uDBFF\uDC00-\uDFFF] matches all non-BMP characters — U+10000…U+10FFFF, which contains most of all emojis but also contains huge non-emoji characters.

So, as you say “[\uD800-\uDBFF\uDC00-\uDFFF]” was working, the equivalent pattern in NSRegularExpression is "[\\U00010000-\\U0010FFFF]".

(Addition) To see Unicode code points in your string literal:

For your example string, I get:

 

 

Leave a Reply

Your email address will not be published.