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.匿名函数中 ...
随机推荐
- 3386 二分图 洛谷luogu [模版]
题目背景 二分图 感谢@一扶苏一 提供的hack数据 题目描述 给定一个二分图,结点个数分别为n,m,边数为e,求二分图最大匹配数 输入输出格式 输入格式: 第一行,n,m,e 第二至e+1行,每行两 ...
- [转]Qt中定时器使用的两种方法
Qt中定时器的使用有两种方法,一种是使用QObject类提供的定时器,还有一种就是使用QTimer类. 其精确度一般依赖于操作系统和硬件,但一般支持20ms.下面将分别介绍两种方法来使用定时器. 方法 ...
- MATLAB——LMS算法(△规则Delta Rule)
- PAT A1033 To Fill or Not to Fill (25 分)——贪心
With highways available, driving a car from Hangzhou to any other city is easy. But since the tank c ...
- mysql分表操作
一般分表操作有垂直拆分和水平拆分.顾名思义. 1. 垂直拆分是指,这个表的列,即字段,要拆分成两个或多个表. 这个应用场景比如:这个表字段,几个都是int.datetime等,有那么一个是text类 ...
- CF1056E Check Transcription 字符串哈希
传送门 暴力枚举\(0\)的长度,如果对应的\(1\)的长度也是一个整数就去check是否合法.check使用字符串哈希. 复杂度看起来是\(O(st)\)的,但是因为\(01\)两个数中数量较多的至 ...
- C#集合Collections购物车Shopping Cart
这篇是对象与集合操练,物件的创建,集合的一些基本功能,如添加,编辑,删除等功能. 对象,即是网店的商品物件,Insus.NET只为其添加2个属性,物件的ID的Key和名称ItemName以及2个构造函 ...
- centos7 清除系统日志、历史记录(包括history)、登录信息
history: # echo > .bash_history //清除保存的用户操作历史记录 # history -cw //清除所有历史 centos7 清除系统日志.历史记录.登录信息: ...
- System.Data.SqlClient.SqlException:“对象名 'customer' 无效。"
连接数据库出错, 错误原因:表名错误.
- 基于RC4加密算法的图像加密
基于RC4加密算法的图像加密 某课程的一个大作业内容,对图像加密.项目地址:https://gitee.com/jerry323/RC4_picture 这里使用的是RC4(流.对称)加密算法,算法流 ...