After a successful match the $+[0] variable indicates the offset into the original string that the expression stopped matching at. Similarly the $-[0] variable is going to tell you the offset of the start of the expression match. If you then combine those two pieces of information with substr() you'll be able to extract all the text between your two expression matches.
my $str = 'a' . ('_' x 100) . 'b'; my $start = $str =~ /a/ ? $+[0] : 0; my $end = $str =~ /b/ ? $-[0] : 0; my $ext = substr $str, $start, $start - $end; print $ext;
In reply to Re: print data between two regular expressions
by diotalevi
in thread print data between two regular expressions
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |