const regex = new RegExp('\\s*
(
(?<type>int(?:\\s+long|\\s+short)?|double(?:\\s+long)?|
long(?:\\s+int|\\s+double)?|short(?:\\s+int)?|float|char)
|
(?<error>\\w+|\\w+\\s*\\,)
)
\\s+
(?:
(?:
(?:
(?<error>int|double|float|char|long|short|[^,;a-zA-Z_].+?|[^,;]+?(?:\\s+\\w+?)+)
|
(?<id>[a-zA-Z_][a-zA-Z_0-9]*)
)
(?:\\s*\\[\\s*[1-9]\\d*\\s*\\])*
)
\\s*
(?:\\,\\s*|(?=\\;))
)+
\\s*\\;\\s*', 'gm')
const str = `int
abv, cde, doub1lel,ded, cto, int1;
float ng23423, _ga45,
astories;
int af , f;
int a, b, c;int short alt ;
long double fgd [ 1 ], [1] , wef ;
char _a[1], fi [
3
] [ 10] [ 4 ] ,g[1];int qw;`;
// 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