xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub! js replace all solutions

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

bug

xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
js replace all
solutions

`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

xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
js replace all
solutions

`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"

xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
js replace all
solutions

Unicode

xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
js replace all
solutions

https://*.com/questions/44669073/regular-expression-to-match-and-split-on-chinese-comma-in-javascript

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*(?:uD805uDC4D|uD836uDE87|[u002Cu02BBu060Cu2E32u2E34u2E41u2E49u3001uFE10uFE11uFE50uFE51uFF0CuFF64u00B7u055Du07F8u1363u1802u1808uA4FEuA60DuA6F5u02BDu0312u0313u0314u0315u0326u201A])s*/


xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
js replace all
solutions

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"]

xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
js replace all
solutions

https://www.cnblogs.com/xgqfrms/p/10954098.html


Array flat(Infinity)

xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
js replace all
solutions

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™, xgqfrms® : xgqfrms's offical website of GitHub!
js replace all
solutions



xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
js replace all
solutions

©xgqfrms 2012-2020

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