experience(years)d.o.b (dd/mm/yyyy)
-- 如何使用node中的单个replace函数从字符串中删除(),.,空格。我想得到的是
experienceyearsdobddmmyyyy
/pgm将XL转换为json。
const exceltojson = require('xlsx-to-json');
const fs = require('fs');
exceltojson({
input: "xl.xlsx",
output: 'xl.txt',// Don't need output
sheet: 'student_Details'
},
function(err, result) {
if (err) {
console.error(err);
return;
}
else{
console.log(result+' result')
console.log(result)
}
const newResult = result.map(obj => {
const newObj = Object.keys(obj).reduce((acc, key) => {
const newKey = key.replace(/ /g, '').toLowerCase();
acc[newKey] = obj[key];
console.log(newKey+' newKey ')
return acc;
}, {});
return newObj;
});
fs.writeFileSync('xl.json', JSON.stringify(newResult));
}
)
> re = /[\(\)\/\.\ ]+/g
/[\(\)\/\.\ ]+/g
> s="(10/04/2020)"
'(10/04/2020)'
> s.replace(re, "")
'10042020'
你可以使用regex来替换所有这些chracters。
let str = "experience(years)d.o.b (dd/mm/yyyy)";
function stripedStr(s){
return s.replace(/[\(,\),\.,\/,\-,\_, ,]/g, "");
}
console.log(stripedStr(str));