Nodejs,javascript filter Emoj expression

Source: Internet
Author: User

1 Preface

Since the nickname with Emoj expression cannot be stored in MySQL character_set_server= UTF8 mode, the reference article [1], changed to UTF8MB4, invalid (may use the wrong method).

The general idea is to filter the nickname Emoj expression, get filtered nickname.

2 Code

function Filternicknamewithemoj (nickname) {    var regstr =/[\ud83c|\ud83d|\ud83e][\udc00-\udfff][\u200d|\ufe0f]|[ \ud83c|\ud83d|\ud83e][\udc00-\udfff]| [0-9|*|#]\ufe0f\u20e3| [0-9|#]\u20e3| [\u203c-\u3299]\ufe0f\u200d| [\u203c-\u3299]\ufe0f| [\u2122-\u2b55]|\u303d| [\a9|\ae]\u3030|\ua9|\uae|\u3030/ig;    var nickname_filter= "";    Regstr.test (nickname) will fail once, whether or not the REGSTR is written about    if (Regstr.test (nickname)) {        Nickname_filter = Nickname.replace (Regstr, "");        Nickname_filter = Removeblank (nickname_filter);        return nickname_filter;    }    return nickname;} function Removeblank (str) {    str = Str.trim ();    var ret = "";    for (var i = 0; i < str.length; i++) {        if (str[i]! = ") {            ret+=str[i];        }    }    return ret;}

Regular expressions and other representations, this regular expression can filter ios10+ all emoticons pack [2]

3 references

[1] Save emoji to MySQL via node. js

[2] Https://www.cnblogs.com/zt-blog/p/6773854.html

[3] https://segmentfault.com/q/1010000005840528

[4] https://segmentfault.com/q/1010000011875872/a-1020000011876055

[5] Public platform nickname garbled emoji expression filter

Nodejs,javascript filter Emoj expression

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.