2 回答

TA貢獻(xiàn)2019條經(jīng)驗 獲得超9個贊
您可以使用 來實現(xiàn)這regex一點(diǎn),例如:
const string = "('UYHN7687YTF09IIK762220G6','Second')";
const regex = /'(.*?)'/ig
// Long way
const array = [];
let match;
while (match = regex.exec(string)){
array.push(match[1]);
};
console.log(array)
// Fast way
console.log([...string.matchAll(regex)].map(i => i[1]))

TA貢獻(xiàn)1850條經(jīng)驗 獲得超11個贊
let given_string = "('UYHN7687YTF09IIK762220G6','Second')";
// first remove the both ()
given_string = given_string.substring(1); // remove (
given_string = given_string.substring(0, given_string.length - 1); // remove )
let expected_array = given_string.split(',');
console.log(expected_array);
添加回答
舉報