in reply to help regarding a regular expression in perl
You can also grab all matches at once to an array:
c:\@Work\Perl>perl -wMstrict -le "my $s = qq{xxx \@B grab \n this \@E yy zzzz \@B and \n this \n too \@ +E qq}; print qq{[[$s]]}; ;; my @captures = $s =~ m{ \@B .*? \@E }xmsg; print qq{<<$_>>} for @captures; " [[xxx @B grab this @E yy zzzz @B and this too @E qq]] <<@B grab this @E>> <<@B and this too @E>>
Update 1:
$string=" ... @begin ... @end ..." .....Note that arrays like @begin @end interpolate into interpolating or "double-quote" strings like " ... " and qq/ ... / along with $scalar scalars. Neither interpolate into non-interpolating 'single-quote' strings. Please see Quote and Quote-like Operators and Quote-Like Operators in perlop.
Update 2: Or if you mean you want to grab only the sub-string between the delimiting patterns, add a coupla parens:
(You could also do this without a capture group using look-arounds, but let's let this stand for now.)c:\@Work\Perl>perl -wMstrict -le "my $s = qq{xxx \@B grab \n this \@E yy zzzz}; print qq{[[$s]]}; ;; my @captures = $s =~ m{ \@B (.*?) \@E }xmsg; print qq{<<$_>>} for @captures; " [[xxx @B grab this @E yy zzzz]] << grab this >>
|
|---|