我希望在字串中插入引號,但保留其他所有內容。所以,一個示例字串:
' "2020-10-10",8000,"Hello" '
我想在 8000 左右(或任何數字)加上引號。所以:
' "2020-10-10","8000","Hello" '
我將如何在正則運算式中做到這一點?
uj5u.com熱心網友回復:
我不是正則運算式的專家,但你可以做到,你只需要做兩次。因為我想不出一種方法來尋找“,char 或 char”。
function test() {
try {
let a = ' "2020-10-10",8000,"Hello" ';
a = a.replace(/,/g,'","');
a = a.replace(/""/g,'"');
console.log(a);
}
catch(err) {
console.log(err);
}
}
7:26:23 AM Notice Execution started
7:26:23 AM Info "2020-10-10","8000","Hello"
7:26:23 AM Notice Execution completed
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/524235.html
