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'(这两个用作示例,其他为随机 ...
随机推荐
- spring restTemplate 进行http请求的工具类封装
本文为博主原创,未经允许不得转载: 1.对常用调用的方法进行封装: import org.springframework.http.HttpHeaders; import com.alibaba.fa ...
- 判断2个list中是否有相同的数据(相交)Collections.disjoint
https://blog.csdn.net/yang_niuxxx/article/details/85092490 private void initData() { for (int i = 0; ...
- 利用powershell隐藏执行后门
运行后门时,有些后门不能中断.双击运行这种后门会产生一个黑框. 一条命令就能使其在后台执行 命令解释: start-process启动一个进程 -windowstyle窗口样式 hidden隐藏
- Centos7 安装RabbitMQ 3.6.1
如果你看过前两章对RabbitMQ已经有了一定了解,现在已经摩拳擦掌,来吧动手吧! 用什么系统 本文使用的是Centos7,为了保证对linux不太熟悉的伙伴也能轻松上手(避免折在安装的路上),下面是 ...
- sql 工具类function
--判断是否为整数 create or replace function is_number(param VARCHAR2) return NUMBER is v_num NUMBER; begin ...
- 2019 China Collegiate Programming Contest Qinhuangdao Onsite F. Forest Program(DFS计算图中所有环的长度)
题目链接:https://codeforces.com/gym/102361/problem/F 题意 有 \(n\) 个点和 \(m\) 条边,每条边属于 \(0\) 或 \(1\) 个环,问去掉一 ...
- AtCoder Beginner Contest 172
比赛链接:https://atcoder.jp/contests/abc172/tasks A - Calc 题意 给出一个正整数 $a$,计算 $a + a^2 + a^3$ .($1 \le a ...
- hdu3905 Sleeping (区间dp)
Problem Description ZZZ is an enthusiastic ACMer and he spends lots of time on training. He always s ...
- python的threading的使用(join方法,多线程,锁threading.Lock和threading.Condition
一.开启多线程方法一 import threading,time def write1(): for i in range(1,5): print('1') time.sleep(1) def wri ...
- dict与set -- Python
dict(字典):用空间换取时间,占据空间大,但查询速度快,键值对(key:value),key唯一 d = {'Michael': 95, 'Bob': 75, 'Tracy': 85} 由于一个k ...