[英]JavaScript regular expression to remove comma in number comma number
"12,56,7abc,fgh" ===> "12567abc,fgh"
"1,245abc,1a" ===> "1245abc,1a"
"1,2,3,4,5abc" ===> "12345abc"
如何刪除(number),(number)
格式的逗號?
對於測試
const array = ["12,56,7abc,fgh", "1,245abc,1a", "1,2,3,4,5abc"]
const answer = ["12567abc,fgh", "1245abc,1a", "12345abc"]
function formatter(string){
// here
return // string.replace('', '') ??
}
array.map((el, i) => {
const formatted = formatter(el)
if(answer[i] === formatted){
console.log('Success. formatted: ', formatted)
} else {
console.log('Failed. formatted: ', formatted)
}
})
str.replace(/(?<=\d),(?=\d)/g, '')
(?<=\d): 向后看 - 一個數字
(?=\d): 前瞻 - 一個數字
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.