2 回答
TA贡献1848条经验 获得超2个赞
您可以执行以下操作:
const songs = [
"Lophelia -- MYTCH [Acoustic Prog-Rock/Jazz] (2019)",
"Julia Jacklin - Pressure to Party [Rock] (2019)",
"The Homeless Gospel Choir - I'm Going Home [Folk-Punk] (2019) cover of Pat the Bunny | A Fistful of Vinyl",
"Lea Salonga and Simon Bowman - The last night of the world [musical] (1990)",
"Lophelia -- MYTCH [Acoustic Prog-Rock/Jazz]",
"Death - $uicideboy$",
"SNFU -- Joni Mitchell Tapes [Punk/Alternative] (1993)",
"Title - Aritst (2000)",
"Something strange and badly formatted without any artist [Classical]",
];
const trailingRgx = /\s*((\[[^\]]+\])|(\(\d+\))).*$/;
const details = songs.map(song => {
const splitted = song.split(/\s+\-+\s+/);
let title = splitted[0];
let artist = splitted[1];
if (splitted.length >= 2) {
artist = artist.replace(trailingRgx, '');
} else {
title = title.replace(trailingRgx, '');
}
return {
title,
artist
}
});
console.log(details);
添加回答
举报