Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
633 views
in Technique[技术] by (71.8m points)

regex - javascript unicode emoji regular expressions

i want to replace all emoji in string with icon now i successfully replaced those {:) :D :P :3 <3 XP .... etc} to icon so if user write :) this on string its will replace with an icon but i got an problem what if user paste direct the unicode ?? that's equal to :) so what i need its

how can i change unicode icon to javascript regular expressions something like ud800-udbff i have many emoji so i want the idea about convert them and after convert them i want to match them with regular expressions

ex : ??wew?? change those emoji to

uD83DuDE01|uD83DuDE4F| i don't know how to change them so i need to know how to change any emoji to those character

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In ECMAScript 6 you should be able to detect it in a fairly simple way. I have compiled a simple regex comprising of different Unicode blocks namely:

Regex:

/[u{1f300}-u{1f5ff}u{1f900}-u{1f9ff}u{1f600}-u{1f64f}u{1f680}-u{1f6ff}u{2600}-u{26ff}u{2700}-u{27bf}u{1f1e6}-u{1f1ff}u{1f191}-u{1f251}u{1f004}u{1f0cf}u{1f170}-u{1f171}u{1f17e}-u{1f17f}u{1f18e}u{3030}u{2b50}u{2b55}u{2934}-u{2935}u{2b05}-u{2b07}u{2b1b}-u{2b1c}u{3297}u{3299}u{303d}u{00a9}u{00ae}u{2122}u{23f3}u{24c2}u{23e9}-u{23ef}u{25b6}u{23f8}-u{23fa}]/ug

Playground: play around with emoji and regex

This answer doesn't directly answer the question but gives a fair insight on how to handle emoji using Unicode blocks and ES6.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...