I am new to typescript, I want to strip the timestamp from a file name.
Filenames can be like
FileName_20210210050124592.xml or FileName_20210210050124592_2.xml
I only want to remove the timestamp (I want to keep the _2 in the second filename)
This is what I have tried so far which works,
let fileName: string = "FileName_20210210050124592.xml";
let newFileName: string;
if((fileName.match(/_/g)||[]).length>1){
newFileName = fileName.replace(/_.*_/, '_');
}
else{
newFileName = fileName.replace(/_.*\./, '.');
}
console.log(newFileName);
Is there a better way to do it or can I improve this code?