js replace all
js replace all
https://stackoverflow.com/questions/1144783/how-can-i-replace-all-occurrences-of-a-string
bug

`133,456, 789`.replace(`,`,`,`);
// "133,456, 789"
`133,456, 133,456, 789`.replace(`,`,`,`);
// "133,456, 133,456, 789"
`133,456, 133,456, 789`.replace(`/,/ig`,`,`);
// "133,456, 133,456, 789"
`133,456, 133,456, 789`.replace(`/\,/ig`,`,`);
// "133,456, 133,456, 789"
`133,456, 133,456, 789`.replace(`//,/g`,`,`);
// "133,456, 133,456, 789"
`133,456, 133,456, 789`.replace(`/\,/ug`,`,`);
// "133,456, 133,456, 789"
`133,456, 133,456, 789`.replace(`/,/ug`,`,`);
// "133,456, 133,456, 789"
`133,456, 133,456, 789`.replace(`/[\u2018]/ug`,`,`);
// "133,456, 133,456, 789"
`133,456, 133,456, 789`.replace(`/\u2018/ug`,`,`);
// "133,456, 133,456, 789"
`133,456, 133,456, 789`.replace(`/\p{P}/g`,`,`);
// "133,456, 133,456, 789"
`133,456, 133,456, 789`.replace(`/[\u3002|\uff1f|\uff01|\uff0c|\u3001|\uff1b|\uff1a|\u201c|\u201d|\u2018|\u2019|\uff08|\uff09|\u300a|\u300b|\u3008|\u3009|\u3010|\u3011|\u300e|\u300f|\u300c|\u300d|\ufe43|\ufe44|\u3014|\u3015|\u2026|\u2014|\uff5e|\ufe4f|\uffe5]/g`,`,`);
// "133,456, 133,456, 789"
solutions
regex & /regex /ig

`133,456, 133,456, 789`.replace(/(\p{Script=Hani})+/gu,`,`);
// "133,456, 133,456, 789"
`133,456, 133,456, 789`.replace(/\,/ig,`,`);
// "133,456, 133,456, 789"
`133,456, 133,456, 789`.replace(`/\,/ig`,`,`);
// "133,456, 133,456, 789"
`133,456, 133,456, 789`.replace(/[\u3002|\uff1f|\uff01|\uff0c|\u3001|\uff1b|\uff1a|\u201c|\u201d|\u2018|\u2019|\uff08|\uff09|\u300a|\u300b|\u3008|\u3009|\u3010|\u3011|\u300e|\u300f|\u300c|\u300d|\ufe43|\ufe44|\u3014|\u3015|\u2026|\u2014|\uff5e|\ufe4f|\uffe5]/g,`,`);
// "133,456, 133,456, 789"
`133,456, 133,456, 789`.replace(/[\u3002|\uff1f|\uff01|\uff0c|\u3001|\uff1b|\uff1a|\u201c|\u201d|\u2018|\u2019|\uff08|\uff09|\u300a|\u300b|\u3008|\u3009|\u3010|\u3011|\u300e|\u300f|\u300c|\u300d|\ufe43|\ufe44|\u3014|\u3015|\u2026|\u2014|\uff5e|\ufe4f|\uffe5]/ug,`,`);
// "133,456, 133,456, 789"

Unicode

split(/\s*[,,]\s*/)
`133,456, 133,456, 789`.replace(`/\,/ig`,`,`);
// "133,456, 133,456, 789"
`133,456, 133,456, 789`.replace(`/\s*[,,]\s*/ig`,`,`);
// "133,456, 133,456, 789"
`133,456, 133,456, 789`.split(/\s*[,,]\s*/);
// ["133", "456", "133", "456", "789"]
const str = "继续,取消 继续 ,取消";
console.log(str.split(/\s*[,,]\s*/));
// ["继续", "取消 继续", "取消"]
Chinese comma
how to replace all Chinese comma using regex in js
https://en.wikipedia.org/wiki/Comma
/\s*(?:\uD805\uDC4D|\uD836\uDE87|[\u002C\u02BB\u060C\u2E32\u2E34\u2E41\u2E49\u3001\uFE10\uFE11\uFE50\uFE51\uFF0C\uFF64\u00B7\u055D\u07F8\u1363\u1802\u1808\uA4FE\uA60D\uA6F5\u02BD\u0312\u0313\u0314\u0315\u0326\u201A])\s*/

array flat
`133,456, 133,456, 789`.replace(`/\,/ig`,`,`);
// "133,456, 133,456, 789"
`133,456, 133,456, 789`.replace(`/\,/`,`,`);
// "133,456, 133,456, 789"
`133,456, 133,456, 789`.replace(`,`,`,`);
// "133,456, 133,456, 789"
`133,456, 133,456, 789`.replace(`/,/g`,`,`);
// "133,456, 133,456, 789"
"133,456, 133,456, 789".split(`,`).split(`,`);
// Uncaught TypeError:
(anonymous) @ VM265:1
"133,456, 133,456, 789".split(`,`);
// ["133,456", " 133,456", " 789"]
"133,456, 133,456, 789".split(`,`).map(item => item.split(`,`));
// [Array(2), Array(2), Array(1)]
Array.flat("133,456, 133,456, 789".split(`,`).map(item => item.split(`,`)));
// Uncaught TypeError: Array.flat is not a function
"133,456, 133,456, 789".split(`,`).map(item => item.split(`,`)).flat();
// ["133", "456", " 133", "456", " 789"]

https://www.cnblogs.com/xgqfrms/p/10954098.html
Array flat(Infinity)

replaceAll & non-global RegExp
ncaught TypeError: String.prototype.replaceAll called with a non-global RegExp argument at String.replaceAll
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll
let s = `A man, a plan, a canal: Panama`;
// all === g
s.replace(/[^0-9a-zA-Z]/g, ``);
// "AmanaplanacanalPanama"
// once
s.replace(/[^0-9a-zA-Z]/, ``);
// "Aman, a plan, a canal: Panama"
// not set global
s.replaceAll(/[^0-9a-zA-Z]/, ``);
// Uncaught TypeError: String.prototype.replaceAll called with a non-global RegExp argument
// global falg === g
s.replaceAll(/[^0-9a-zA-Z]/g, ``);
// "AmanaplanacanalPanama"
https://leetcode.com/submissions/detail/368182883/

xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
js replace all的更多相关文章
- JS replace()方法-字符串首字母大写
replace() 方法用于在字符串中用一些字符替换另一些字符,或替换一个与正则表达式匹配的子串. replace()方法有两个参数,第一个参数是正则表达式,正则表达式如果带全局标志/g,则是代表替换 ...
- js replace,正则截取字符串内容
1.js replace替换,使用 http://www.jb51.net/article/43949.htm 顺便记录一下 e.g. js获取sql中的可替换参数$id,$name."SE ...
- js replace 全局替换
js 的replace 默认替换只替换第一个匹配的字符,如果字符串有超过两个以上的对应字符就无法进行替换,这时候就要进行一点操作,进行全部替换. <script language="j ...
- js replace全部替换的方法
1.JS replace()方法替换变量(可以对变量进行全文替换) string.replace(new RegExp(key,'g'),"b"); 2.封装 String.pro ...
- js replace 与replaceall实例用法详解
这篇文章介绍了js replace 与replaceall实例用法详解,有需要的朋友可以参考一下stringObj.replace(rgExp, replaceText) 参数 stringObj 必 ...
- js replace 全局替换 以表单的方式提交参数 判断是否为ie浏览器 将jquery.qqFace.js表情转换成微信的字符码 手机端省市区联动 新字体引用本地运行可以获得,放到服务器上报404 C#提取html中的汉字 MVC几种找不到资源的解决方式 使用Windows服务定时去执行一个方法的三种方式
js replace 全局替换 js 的replace 默认替换只替换第一个匹配的字符,如果字符串有超过两个以上的对应字符就无法进行替换,这时候就要进行一点操作,进行全部替换. <scrip ...
- js replace方法第二个参数,远不止你想的那么强大
js replace() 方法,想必大家都不陌生. 定义和用法: replace()方法用于在字符串中用一些字符替换另一些字符,或者替换一个与正则表达式匹配的子串. stringObject.repl ...
- js replace all & replaceAll
js replace all & replaceAll https://scotch.io/tutorials/javascript-replace-all-instances-of-a-st ...
- Js replace() 学习笔记
最近捣鼓着学习Js,发现replace()真的很有用,替换功能杠杠的棒. 接下来看看我遇到的问题: 有两个随机给出的字符串,字符串1'xxxxxx',字符串2'====T'(这两个用作示例,其他为随机 ...
随机推荐
- makefile自动生成学习
https://www.cnblogs.com/jrglinux/p/6964169.html 关键是如何写Makefile.am 其他的交给 自动工具完成 添加一个 很好的博客 学习下 https ...
- ASP.NET Core 5.0 MVC中的 Razor 页面 介绍
Razor 是一个用于将基于服务器的代码嵌入到网页中的标记语法. Razor语法由 Razor 标记.c # 和 HTML 组成. 通常包含 Razor 的文件的扩展名 cshtml Razor 语法 ...
- CF401C
扯在前面 本题的英文翻译很有意思,很符合CF大多题的故事风格,但是luogu的翻译更过于直白易懂 如果让我看英文故事做题我怕我都不知道该怎么下手 正文 题意: 构造一个01序列,包含n个0,m个1要求 ...
- python -m http.server 搭建一个简易web下载服务器
在打vulnhub靶场的时候遇到的一个问题 目录 一.进到需要发送的安装包目录 二.开启http服务 三.访问服务器 一.进到需要发送的安装包目录 比如设置一个专门发送,传输的文件的文件夹,cmd命令 ...
- EIGRP和OSPF__邻居发现
散知识点 1.当配置通配符时,它们的取值总是块尺寸减去1:/28的块尺寸为16,因此当我们添加网络声明时,使用了此子网号和一个在需配置的八位位组中添加值为15的通配符. 邻居发现 1.在EIGRP路由 ...
- ThreadLocal全面解析,一篇带你入门
===================== 大厂面试题: 1.Java中的引用类型有哪几种? 2.每种引用类型的特点是什么? 3.每种引用类型的应用场景是什么? 4.ThreadLocal你了解吗 5 ...
- 如何学习Java?从标识符开始
标识符 1.定义 Java对各种变量.方法和类等要素命名时使用的字符序列称为标识符(包含但不限于:类名.变量名.方法名.接口名.包名--) 2.命名规则 1.由26个英文字母大小写,0-9,_或$组成 ...
- HDU 6264 (深搜,数论)
题目链接 题意 求\(\sum_{d|n}\phi (d) \times {n\over d}\),其中\(\phi(n) = n\prod_{p|n}({1-{1\over p}})\) 分析 将\ ...
- HDU-4315 Climbing the Hill
题目链接 先回到阶梯博弈的裸题中,比如POJ-1704,所有的块只能向左移并且不能跨越,这个向左移的结果我们可以理解为将左边的宽度减少使得右边的宽度增加,等同于阶梯模型中将石子从高阶移动到低阶.那么最 ...
- 神奇C语言的字串处理库函数
头文件:#incldue<string.h> 定义:strstr(str1,str2) 函数用于判断字符串str2是否是str1的子串.如果是,则该函数返回str2在str1中首次出现的地 ...