On Aug 21, Gibbs Tanton - tgibbs said:
>You may want to try $` $& and $'
>my $string = 'abcdefhij';
>$string =~ /(def)/;
>print "$`:$&:$'";
>
>**this prints: abc:def:hij
>
>
>However, use of $`, $&, and $' will slow down ALL of your regular
>expressions.
Which is why, in Perl 5.6, we have the @- and @+ arrays, which contain
offsets in the string of various parts of the match:
substr($str, 0, $-[0]) # analogous to $`
substr($str, $-[0], $+[0] - $-[0]) # analogous to $&
substr($str, $+[0]) # analogous to $'
The other elements in these arrays are for the $DIGIT variables.
substr($str, $-[1], $+[1] - $-[1]) # analogous to $1
substr($str, $-[2], $+[2] - $-[2]) # analogous to $2
...
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]