const regex = /([„]([^„]+)[“]|[“]([^“]+)[”]|["]([^"]+)["])/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('([„]([^„]+)[“]|[“]([^“]+)[”]|["]([^"]+)["])', 'g')
const str = `Then he spoke! Finally! Reached out his hands. He wanted… the dead baby rabbit? That was what this was all about? Aiden just wanted the little thing in his hands? "Well, just ask, right?" Grayson tried a smile and laid the small, dead and very bloody body into his brother’s hands. "Don’ you worry. Just ask. You can have it." Aiden could get everything Grayson had, there was never a doubt. He even would have given him any ice cream or sweet he ever wanted. Because it was Aiden. "Is everythin' okay now?" Was Aiden happy now? Well…. as happy as Aiden could get. He didn’t look like it. But he never looked happy, anyway.
Then he spoke! Finally! Reached out his hands. He wanted… the dead baby rabbit? That was what this was all about? Aiden just wanted the little thing in his hands? „Well, just ask, right?“ Grayson tried a smile and laid the small, dead and very bloody body into his brother’s hands. „Don’ you worry. Just ask. You can have it.“ Aiden could get everything Grayson had, there was never a doubt. He even would have given him any ice cream or sweet he ever wanted. Because it was Aiden. „Is everythin’ okay now?“ Was Aiden happy now? Well…. as happy as Aiden could get. He didn’t look like it. But he never looked happy, anyway.
Then he spoke! Finally! Reached out his hands. He wanted… the dead baby rabbit? That was what this was all about? Aiden just wanted the little thing in his hands? “Well, just ask, right?” Grayson tried a smile and laid the small, dead and very bloody body into his brother’s hands. “Don’ you worry. Just ask. You can have it.” Aiden could get everything Grayson had, there was never a doubt. He even would have given him any ice cream or sweet he ever wanted. Because it was Aiden. “Is everythin’ okay now?” Was Aiden happy now? Well…. as happy as Aiden could get. He didn’t look like it. But he never looked happy, anyway. `;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions