const regex = /\* LIST \((?<Markers>.*)\) \"\/\" (?<folder>.*?)$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('\\* LIST \\((?<Markers>.*)\\) \\"\\\/\\" (?<folder>.*?)$', 'gm')
const str = `* LIST (\\HasChildren) "/" INBOX/Arkabit
* LIST (\\HasNoChildren) "/" "INBOX/Arkabit/Flora (SAP)"
* LIST (\\HasNoChildren) "/" INBOX/BRW
* LIST (\\HasNoChildren) "/" INBOX/Chiptronics
* LIST (\\HasNoChildren) "/" INBOX/CRMB1.COM
* LIST (\\Marked \\HasChildren) "/" INBOX/CVA
* LIST (\\HasNoChildren) "/" INBOX/CVA/Contabilista
* LIST (\\HasNoChildren) "/" INBOX/CVA/Maxflex
* LIST (\\HasNoChildren) "/" INBOX/Decorlux
* LIST (\\HasNoChildren) "/" INBOX/Fabiano
* LIST (\\HasNoChildren) "/" INBOX/Fabielle
* LIST (\\HasNoChildren) "/" INBOX/Gamma
* LIST (\\HasNoChildren) "/" INBOX/Integrate
* LIST (\\HasNoChildren) "/" INBOX/Kelli
* LIST (\\HasNoChildren) "/" INBOX/Laborclin
* LIST (\\HasNoChildren) "/" INBOX/Macrosul
* LIST (\\HasChildren) "/" INBOX/MadeiraMadeira
* LIST (\\HasNoChildren) "/" INBOX/MadeiraMadeira/BRW
* LIST (\\HasNoChildren) "/" INBOX/MadeiraMadeira/Eglo
* LIST (\\HasNoChildren) "/" "INBOX/MadeiraMadeira/Full Fit"
* LIST (\\HasNoChildren) "/" "INBOX/MadeiraMadeira/Glass Mosaic"
* LIST (\\Marked \\HasNoChildren) "/" INBOX/MadeiraMadeira/Luciin
* LIST (\\HasNoChildren) "/" INBOX/MadeiraMadeira/Rojemac
* LIST (\\HasNoChildren) "/" "INBOX/Mercado do Alarme"
* LIST (\\Marked \\HasChildren) "/" INBOX/Stuff
* LIST (\\HasNoChildren) "/" INBOX/Stuff/Importado
* LIST (\\Marked \\HasNoChildren) "/" INBOX/Stuff/Ita&APo-
* LIST (\\Marked \\HasNoChildren) "/" INBOX/Stuff/Literal
* LIST (\\HasChildren) "/" INBOX/Stuff/News
* LIST (\\HasNoChildren) "/" INBOX/Stuff/News/Linkedin
* LIST (\\HasNoChildren) "/" INBOX/Stuff/News/Microsoft
* LIST (\\HasNoChildren) "/" INBOX/Stuff/News/SAP
* LIST (\\Marked \\HasNoChildren) "/" INBOX/Stuff/Postman
* LIST (\\HasChildren) "/" INBOX/Stuff/PrimaERP
* LIST (\\HasNoChildren) "/" INBOX/Stuff/PrimaERP/Faturas
* LIST (\\Marked \\HasNoChildren) "/" INBOX/Stuff/VSOnline
* LIST (\\HasNoChildren) "/" "INBOX/Suporte | CRMSAP"
* LIST (\\HasNoChildren) "/" INBOX/Umbler
\$ OK LIST completed.
`;
// 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