How to get specific text from a string in regex

I have a string from which I need to extract specific texts

let str = 'id = "Test This is" id ="second" abc 123 id ="third-123"';
let res = str.match(/[^id ="[](.*)[^]]/g);
console.log(res);

I want the texts in ids only ['Test This is','second','third-123'] But I am getting [ 'Test This is" id ="second" abc 123 id ="third-123"' ] The whole text after first id which I don’t want.I need help with the pattern.

Answer

Your pattern uses a negated character class where you exclude matching the listed individual characters, and also exclude matching [ and ] which are not present in the example data.

That way you match the first char T in the string with [^id ="[] and match the last char ; in the string with [^]] and the .* captures all in between.

I would suggest using a negated character class to exclude matching the " instead:;

bids*=s*"([^"]*)"

Regex demo

let str = 'id = "Test This is" id ="second" abc 123 id ="third-123"';
let res = str.matchAll(/bids*=s*"([^"]*)"/g);
console.log(Array.from(str.matchAll(/bids*=s*"([^"]*)"/g), m => m[1]));