const regex = /((RESERVADAS|[A-Z]+)[(][)][ ]*[\t]*[\r\n|\n]*([{][\r\n|\n]*([\t]*[ ]*[0-9]+[ ]*[=][ ]*(['][A-Z]+['])[\r\n|\n]*)+[\r\n|\n]*[}][\r\n|\n]*)*)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('((RESERVADAS|[A-Z]+)[(][)][ ]*[\\t]*[\\r\\n|\\n]*([{][\\r\\n|\\n]*([\\t]*[ ]*[0-9]+[ ]*[=][ ]*([\'][A-Z]+[\'])[\\r\\n|\\n]*)+[\\r\\n|\\n]*[}][\\r\\n|\\n]*)*)', 'gm')
const str = `RESERVADAS()
{
18 = 'PROGRAM'
19 = 'INCLUDE'
20 = 'CONST'
21 = 'TYPE'
22 = 'VAR'
23 = 'RECORD'
24 = 'ARRAY'
25 = 'OF'
26 = 'PROCEDURE'
27 = 'FUNCTION'
28 = 'IF'
29 = 'THEN'
30 = 'ELSE'
31 = 'FOR'
32 = 'TO'
33 = 'WHILE'
34 = 'DO'
35 = 'EXIT'
36 = 'END'
37 = 'CASE'
38 = 'BREAK'
39 = 'DOWNTO'
}
COSO()
{
19='A'
}
`;
// 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