I'm receiving data in this form
('FCA',)
('JP NIC',)
('JP CHI',)
('2022-03-04T07:18:36.468Z',)
I want to clean up to remove Brackets, string quote and comma
FCA
JP NIC
JP CHI
2022-03-04T07:18:36.468Z
I'm trying to use substring() But problem is number of characters in this data can be changed but these value are constant and I want to remove them ('',). How I can do this ?
Use this regex:
const regex = /\('([^']+)',\)/g
const output = input.replace(regex, '$1');
// explain: / \( ' ( [^']+ ) ',\) / g
// 1 2 3 4 5 6 7 8 9
( (character / to escape)''',)$1 in code is first group match regex (start with 4 and end with 6)const input = `('FCA',)
('JP NIC',)
('JP CHI',)
('2022-03-04T07:18:36.468Z',)`;
const output = input.replace(/\('([^']+)',\)/g, '$1');
console.log(input)
console.log('// =>')
console.log(output)
You could use a regex replacement with a capture group:
var inputs = ["('FCA',)", "('JP NIC',)", "('JP CHI',)", "('2022-03-04T07:18:36.468Z',)"];
var outputs = inputs.map(x => x.replace(/\('(.*?)',\)/g, "$1"));
console.log(outputs);