Flip-flop in either configuration is probably the more natural choice, but a regular expression was the spec, so I give you:
#!/usr/local/bin/perl
use strict;
use warnings;
$_ = <<'EOT';
// useless comment
Some Code
//**********************************************************
//
//I need that text
// And that also
//
//**********************************************************
Some Code
//**********************************************************
//
//I need that text
// And that also
//
//**********************************************************
Some Code
// useless comment
Some Code
//**********************************************************
//
//I need that text
// And that also
// And some more
//
//**********************************************************
Some Code
// useless comment
EOT
my $i = 0;
while (m|^//\*+\s*^.+?(\w[^*]+\w).+?^//\*+\s*$|smg) {
printf "%d:\n%s\n\n", ++$i, $1;
}
__END__
1:
I need that text
// And that also
2:
I need that text
// And that also
3:
I need that text
// And that also
// And some more
There's no way in a single autonomous expression to grab a variable number of fields, so I had to grab the whole chunk. If you know each one is 2 lines, you could use
^//\*+\s+^.+?^//\s*(\w.+?)\s*^//\s*(\w.+?$).+?^//\*+\s+$
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.