js正则查询匹配语句里面的“凋谢”、“鼓掌”等替换成图片的方法
程序员文章站
2022-04-07 09:55:24
js正则查询匹配语句里面的“凋谢”、“鼓掌”等替换成图片的方法
// 转成本地图片地址
function vodChange...
js正则查询匹配语句里面的“凋谢”、“鼓掌”等替换成图片的方法
// 转成本地图片地址 function vodChangeUrl2Local(match){ var code = ''; switch(match){ case "【太快了】": code = match.replace(match,'<img src="/assets/img/emotion/feedback.quickly.png">'); break; case "【太慢了】": code = match.replace(match,'<img src="/assets/img/emotion/feedback.slowly.png">'); break; case "【赞同】": code = match.replace(match,'<img src="/assets/img/emotion/emotion.nod.png">'); break; case "【反对】": code = match.replace(match,'<img src="/assets/img/emotion/feedback.against.png">'); break; case "【鼓掌】": code = match.replace(match,'<img src="/assets/img/emotion/feedback.applaud.png">'); break; case "【值得思考】": code = match.replace(match,'<img src="/assets/img/emotion/feedback.think.png">'); break; case "【礼物】": code = match.replace(match,'<img src="/assets/img/emotion/chat.gift.png">'); break; case "【愤怒】": code = match.replace(match,'<img src="/assets/img/emotion/emotion.angerly.png">'); break; case "【鄙视】": code = match.replace(match,'<img src="/assets/img/emotion/emotion.bs.png">'); break; case "【伤心】": code = match.replace(match,'<img src="/assets/img/emotion/emotion.cry.png">'); break; case "【再见】": code = match.replace(match,'<img src="/assets/img/emotion/emotion.goodbye.png">'); break; case "【高兴】": code = match.replace(match,'<img src="/assets/img/emotion/emotion.laugh.png">'); break; case "【流汗】": code = match.replace(match,'<img src="/assets/img/emotion/emotion.lh.png">'); break; case "【无聊】": code = match.replace(match,'<img src="/assets/img/emotion/emotion.nod.png">'); break; case "【疑问】": code = match.replace(match,'<img src="/assets/img/emotion/emotion.question.png">'); break; case "【你好】": code = match.replace(match,'<img src="/assets/img/emotion/emotion.smile.png">'); break; case "【凋谢】": code = match.replace(match,'<img src="/assets/img/emotion/rose.down.png">'); break; case "【鲜花】": code = match.replace(match,'<img src="/assets/img/emotion/rose.up.png">'); break; default: } return code } // 传值匹配 function vodEmotion2Local(richText){ richText = richText.replace( /【[\u4e00-\u9fa5]+】/gi, function (match, capture) { return vodChangeUrl2Local(match); }); return richText.replace(/color: rgb(0, 0, 0);/gi,'').replace(/COLOR: #000000;/gi,'').replace(/color: rgb(92, 92, 92);/gi,'').replace(/COLOR: #5c5c5c;/gi,'').replace(/<font color=#[^>]+>/ig, "").replace(/<\/font>/ig, ""); }
调用:
var str = '你好啊【鄙视】【凋谢】啦啦啦~' var newStr = vodEmotion2Local(str) //'你好啊<img src="/assets/img/emotion/emotion.bs.png"><img src="/assets/img/emotion/rose.down.png"> 啦啦啦~'
上一篇: 二的狠,都笑出尿来了