1
以下代碼正確匹配{{{
和}}}
之間的所有內容,但示例'line3'因爲括號內容包含換行符。如何配合呢?Javascript匹配包括換行符在內的所有內容
const testcase = `
line1: {{{ content1 }}}
line2: {{{ content2 }}}
line3: {{{
content3
}}}
line4: {{{ content4 }}}
`;
const regex = /^(\s+)(.*?)(\{\{\{ [^]*? \}\}\})/gm;
let match;
while ((match = regex.exec(testcase)) != null) {
console.log(match);
}