const regex = /^((struct *[a-z0-9_]+)|[a-z0-9_]+) *[*a-z0-9_]+\((void|((((struct *[a-z0-9_]+)|[a-z0-9_]+) *[*a-z0-9_]+)(, ((struct *[a-z0-9_]+)|[a-z0-9_]+) *[*a-z0-9_]+)*))\)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^((struct *[a-z0-9_]+)|[a-z0-9_]+) *[*a-z0-9_]+\\((void|((((struct *[a-z0-9_]+)|[a-z0-9_]+) *[*a-z0-9_]+)(, ((struct *[a-z0-9_]+)|[a-z0-9_]+) *[*a-z0-9_]+)*))\\)', 'gm')
const str = `int a_0(void)
int b_1(int a)
int c_2(int a, int b)
void *xmalloc(size_t n)
int main(int argc, char **argv)
void *xmalloc(size_t n)
void release(struct s_block)
int a_(int a, int b)
int main(void)
struct student get_student(char *name)
struct student *grow_2fast(struct student *s, int age_diff)
struct student *grow_2fast(struct student *s, struct hello age_diff)
int main(void)
int print_me(int h1)
/*
**int main(void)
*/`;
// 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