用于在两个双引号中捕获文本的正则表达式

Regex for capturing a text in two double quotes

我正在尝试获取一个正则表达式,它将在下面的示例中找到 text1text2 :

,"blabla "test1" blabla", "another text"

,"blabla "test2" blabla", "another text"

总而言之,我想要双引号之间的所有文本,以及双引号和逗号之间的文本。

这个表达式可能会这样做:

 ".+?"(.+?)".+?"

我们想要的输出在这个捕获组中:

 (.+?)

Demo

const regex = /".+?"(.+?)".+?"/gm;
const str = `,"blabla "test1" blabla", "another text"
,"blabla "test2" blabla", "another text"`;
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}`);
    });
}