xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

js regex variable & Set, Map

js regex variable & Set, Map

regex, variable, Set, Map, 交集, 差集, 并集,

https://stackoverflow.com/questions/494035/how-do-you-use-a-variable-in-a-regular-expression

https://www.hacksparrow.com/javascript-use-variables-with-regular-expressions.html

Regex is not Work for Inner keyword!


let newsTitle = `长安汽车无惧与外资公平竞争`;

let newTitle = `长安无惧与外资公平竞争`;

let newsHighLightTitleBackup = `长安汽车无惧与外资公平竞争`;

let newsHighLightTitle = `长安<span class="audit-label-highlight-color">汽车</span>无惧与外资公平竞争`;

newsHighLightTitleBackup.replace(newTitle, ``);
// "长安汽车无惧与外资公平竞争"

let reg = new RegExp(newTitle);
newsHighLightTitleBackup.replace(reg, ``);
// "长安汽车无惧与外资公平竞争"



js & get two string diff

ES6 & ES next

Map & Set

// Map, order key by insert order

// Set, unique array


https://stackoverflow.com/questions/1187518/how-to-get-the-difference-between-two-arrays-in-javascript/33034768#33034768

https://stackoverflow.com/questions/1187518/how-to-get-the-difference-between-two-arrays-in-javascript/52430020#52430020

//  交集
let intersection = arr1.filter(x => arr2.includes(x));

// 差集
let difference = arr1.filter(x => !arr2.includes(x));

let difference = arr1
                 .filter(x => !arr2.includes(x))
                 .concat(arr2.filter(x => !arr1.includes(x)));

// 补集

// 并集


https://stackoverflow.com/questions/8024102/javascript-compare-strings-and-get-end-difference

https://stackoverflow.com/questions/2167602/optimum-way-to-compare-strings-in-javascript

https://stackoverflow.com/questions/1187518/how-to-get-the-difference-between-two-arrays-in-javascript

https://stackoverflow.com/questions/18050932/detect-differences-between-two-strings-with-javascript


css highlight keywords

let key = `zzz`.toLocaleUpperCase();
let name = `XXXzzzYYYZZZaaazzzCCC`;

let regx = new RegExp(key, "ig");
name.replace(regx, `<span class="highlight-color">${key}</span>`);



refs



©xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


posted @ 2019-03-12 11:11  xgqfrms  阅读(307)  评论(7编辑  收藏  举报