Using js to parse im expressions

Source: Internet
Author: User

The chat record generally stores emoticesCode, Displays emoticon images ..... Effect

You need to write a regular expression to replace the section enclosed in brackets ([]) in textarea with the corresponding image.

The source code is as follows:

// Dml@2012.9.10 emotion parsevar em = [{'id': 1, 'phrase ':' [heap] ', 'url': '1.gif'}, {'id': 2, 'phrase ':' [Giggle] ', 'url': '2.gif'}, {'id': 3, 'phrase': '[Haha]', 'url ': '3.gif '}, {'id': 4, 'phrase': '[cute]', 'url': '4.gif '}, {'id': 5, 'phrase ': '[Poor]', 'url': '5.gif '}, {'id': 6, 'phrase': '[Pick your nostrils]', 'url': '6.gif '}, {'id': 7, 'phrase ':' [Surprised] ', 'url': '7.gif'}, {'id': 8, 'phrase ': '[Shy]', 'url': '8.gif '}, {'id': 9, 'phrase': '[eye widening]', 'url': '9.gif '}, {'id': 10, 'phrase ':' [Shut Up] ', 'url': '10.gif'}, {'id': 11, 'phrase ': '[despise]', 'url': '11.gif'}, {'id': 12, 'phrase ':' [love you] ', 'url': '12.gif '}, {'id': 13, 'phrase ':' [weeping] ', 'url': '13.gif'}, {'id': 14, 'phrase ': '[Smile]', 'url': '14.gif '}, {'id': 15, 'phrase': '[Kiss]', 'url': '15.gif '}, {'id': 16, 'phrase ':' [ill] ', 'url': '16.gif'}, {'id': 17, 'phrase ': '[Happy]', 'url': '17.gif '}, {'id': 18, 'phrase': '[don't bother you]', 'url ': '18.gif '}, {'id': 19, 'phrase': '[left hang]', 'url': '19.gif '}, {'id': 20, 'phrase ':' [Right-Hang] ', 'url': 'animated gif'}, {'id': 21, 'phrase': '[sh]', 'url ': '21.gif'}, {'id': 22, 'phrase ':' [fading] ', 'url': '22.gif'}, {'id': 23, 'phrase ': '[grievance]', 'url': '23.gif '}, {'id': 24, 'phrase': '[vomit]', 'url': '24.gif '}, {'id': 25, 'phrase ':' [yawning] ', 'url': '25.gif'}, {'id': 26, 'phrase ': '[hug]', 'url': '26.gif '}, {'id': 27, 'phrase': '[angry]', 'url': '27.gif '}, {'id': 28, 'phrase ':' [question] ', 'url': '28.gif'}, {'id': 29, 'phrase ': '[pouting]', 'url': '29.gif '}, {'id': 30, 'phrase': '[Bye-bye]', 'url': '30.gif '}, {'id': 31, 'phrase ':' [think] ', 'url': '31.gif'}, {'id': 32, 'phrase ': '[Khan]', 'url': '32.gif '}, {'id': 33, 'phrase': '[Sleepy]', 'url': '33.gif '}, {'id': 34, 'phrase ':' [sleeping] ', 'url': '34.gif'}, {'id': 35, 'phrase ': '[money]', 'url': '35.gif '}, {'id': 36, 'phrase': '[Disappointed]', 'url': '36.gif '}, {'id': 37, 'phrase ':' [cool] ', 'url': '37.gif'}, {'id': 38, 'phrase ': '[flowers]', 'url': '38.gif '}, {'id': 39, 'phrase': '[hum]', 'url': '39.gif '}, {'id': 40, 'phrase ':' [applaud] ', 'url': '40.gif'}, {'id': 41, 'phrase ': '[dizzy]', 'url': '41.gif '}, {'id': 42, 'phrase': '[sad]', 'url': '42.gif '}, {'id': 43, 'phrase ':' [Crazy] ', 'url': '43.gif'}, {'id': 44, 'phrase ': '[black line]', 'url': '44.gif '}, {'id': 45, 'phrase': '[Yin face]', 'url': '45.gif '}, {'id': 46, 'phrase ':' [angry] ', 'url': '46.gif'}, {'id': 47, 'phrase ': '[heart]', 'url': '47.gif '}, {'id': 48, 'phrase': '[sad]', 'url': '48.gif '}, {'id': 49, 'phrase ':' [Pig] ', 'url': '49.gif'}, {'id': 50, 'phrase ': '[OK]', 'url': '50.gif '}, {'id': 51, 'phrase': '[ye]', 'url': '51.gif '}, {'id': 52, 'phrase ':' [good] ', 'url': '52.gif'}, {'id': 53, 'phrase ': '[do not]', 'url': '53.gif '}, {'id': 54, 'phrase': '[like]', 'url': '54.gif '}, {'id': 55, 'phrase ':' [Come] ', 'url': '55.gif'}, {'id': 56, 'phrase ': '[Weak]', 'url': '56.gif '}, {'id': 57, 'phrase': '[candle]', 'url': '57.gif '}, {'id': 58, 'phrase ':' [clock] ', 'url': '58.gif'}, {'id': 59, 'phrase ': '[Cake]', 'url': '59.gif '}, {'id': 60, 'phrase': '[microphone]', 'url': '60.gif '}]; function msgreplace (msghtml) {var regx =/(\ [[\ u4e00-\ u9fa5] * \ W * \]) {1}/g; // search for the regular expression in the "[]" format var rs = msghtml. match (regx); If (RS) {for (I = 0; I <Rs. length; I ++) {for (n = 0; n <em. length; n ++) {If (EM [N]. phrase = Rs [I]) {var T = "

display area. You only need to call the msgreplace method ....

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.