const regex = /(?:\([^\w()]*\w[^()]*\)|\w+\.?)\s•/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?:\\([^\\w()]*\\w[^()]*\\)|\\w+\\.?)\\s•', 'g')
const str = `ALCOHOL DENAT. • FRAGRANCE (PARFUM) • WATER\\AQUA\\EAU • HYDROXYCITRONELLAL • LIMONENE • BENZYL BENZOATE • CITRONELLOL • GERANIOL • COUMARIN • FARNESOL • CITRAL • BENZYL ALCOHOL • CINNAMYL ALCOHOL • LINALOOL • ALCOHOL • DIPROPYLENE GLYCOL • ETHYLHEXYL METHOXYCINNAMATE • BUTYL METHOXYDIBENZOYLMETHANE • ETHYLHEXYL SALICYLATE • TRIS(TETRAMETHYLHYDROXYPIPERIDINOL) CITRATE • DILAURYL THIODIPROPIONATE • TOCOPHEROL • BHT • BENZOIC ACID • RED 4 (CI 14700) • EXT. VIOLET 2 (CI 60730) • YELLOW 6 (CI 15985) <ILN46472>
RED 4 () • EXT. VIOLET 2 (CI 60730) • YELLOW 6 (CI 15985) <ILN46472>
RED 4 (!#\$%) • EXT. VIOLET 2 (CI 60730) • YELLOW 6 (CI 15985) <ILN46472>`;
// 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