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
Innerkeyword!
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
// 交集
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/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>`);
js regex variable & Set, Map的更多相关文章
- JS数组filter()、map()、some()、every()、forEach()、lastIndexOf()、indexOf()实例
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat=&qu ...
- java和js中JSONObject,JSONArray,Map,String之间转换
--------------------------------------------------Java中--------------------------------------------- ...
- react / config\webpack.config.js 编译后去掉map 减小体积 shouldUseSourceMap = false
react / config\webpack.config.js 编译后去掉map 减小体积 shouldUseSourceMap = false
- js & regex & var & highlight
js & regex & var & highlight let key = `ali`.toLocaleUpperCase(); let name = "阿里云计算 ...
- js解析json,js转换json成map,获取map的key,value
json串格式 { "10.10.11.1": { "target_1": "34.2", "target_3": &q ...
- js原生forEach、map与jquery的each、$.each的区别
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...
- js ES6 Set和Map数据结构详解
这篇文章主要介绍了ES6学习笔记之Set和Map数据结构,结合实例形式详细分析了ECMAScript中基本数据结构Set和Map的常用属性与方法的功能.用法及相关注意事项,需要的朋友可以参考下 本 ...
- [Functional Programming 101] Crocks.js -- when to use map and when to use chain?
As a beginner of Crocks.js, it was a problem for we to figure out when to use .map() and when to use ...
- JS中forEach和map的区别
共同点: 1.都是循环遍历数组中的每一项. 2.forEach()和map()里面每一次执行匿名函数都支持3个参数:数组中的当前项item,当前项的索引index,原始数组input. 3.匿名函数中 ...
随机推荐
- rbac组件
创建新项目 新建一个项目untitled,注意django 版本为1.11 修改models.py,增加2个表 from django.db import models class Classes(m ...
- C++反转单链表
单链表 /* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } }; ...
- I2C总线通信
UART 属于异步通信,比如电脑发送给单片机,电脑只负责把数据通过TXD 发送出来即可,接收数据是单片机自己的事情.而 I2C 属于同步通信, SCL 时钟线负责收发双方的时钟节拍, SDA 数据线负 ...
- SkylineGlobe6.5遍历信息树节点方法
//------------------- //searchGeometries function searchGeometries2(parentNode, callbackFunc) { SGWo ...
- 关于Http 传输二维json
传输一维的好说 public static String doPost(String url) { String result = new String(); OutputStream out = n ...
- Luogu3825 NOI2017 游戏 2-SAT
传送门 第一眼看上去似乎是一个3-SAT问题 然而\(d \leq 8\)给我们的信息就是:暴力枚举 枚举\(x\)型地图变成\(a\)型地图还是\(b\)型地图(实际上不要枚举\(c\),因为\(a ...
- BZOJ4614/UVA1742 Oil 计算几何
传送门 题意:在平面直角坐标系中给出$N$条互不相交的.与$x$轴平行.且在$x$轴上方的线段,每一条线段的价值为其长度.求一条不与$x$轴平行的直线,使得与这条直线相交的线段的价值之和最大,求出这个 ...
- Luogu4609 FJOI2016 建筑师 第一类斯特林数
题目传送门 题意:给出$N$个高度从$1$到$N$的建筑,问有多少种从左往右摆放这些建筑的方法,使得从左往右看能看到$A$个建筑,从右往左看能看到$B$个建筑.$N \leq 5 \times 10^ ...
- Luogu2045 方格取数加强版(K取方格数) 费用流
题目传送门 题意:给出一个$N \times N$的方格,每个格子中有一个数字.你可以取$K$次数,每次取数从左上角的方格开始,每一次只能向右或向下走一格,走到右下角结束,沿路的方格中的数字将会被取出 ...
- url 传递中文参数乱码问题的终极解决方法。
估计很多人在做web开发的时候,都会碰到过url传递中文参数,有时候会出现乱码的问题,但有些项目或者环境,又不会有问题.当遇到乱码的时候,上网找了很多解决方案,比如: 页面设置它的编码方式,改成utf ...