在很多聊天中,會有許多表情,這些表情都是類似”[微笑]”的這種,然后寫了一個正則表達式,保留在這里,便于以后使用中.這里的提取支持提取中文.在Node.js 6.10.2下運行通過.
1 let testStr = "now [里斯本] [test002] [ddddd] [adfasd][3234]";
2
3 function getFaceTag(message) {
4 let re = /\[([\u4e00-\u9fa5\w]+)\]/g;
5 let r = {fulltag:[],tags:[]};
6 let m;
7 while(m = re.exec(message)) {
8 r.fulltag.push(m[0]);
9 r.tags.push(m[1]);
10 }
11 return r;
12 }
13
14 let k = getFaceTag(testStr);
15 console.log(k);