use strict;
my $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)
*/';
my $regex = qr/^((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_]+)*))\)/mp;
if ( $str =~ /$regex/g ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
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 Perl, please visit: http://perldoc.perl.org/perlre.html