In article <[EMAIL PROTECTED]>,
[EMAIL PROTECTED] (Waspcatcher) wrote:
> hi,
> how does one extract *just* the matched text in a regular expression,
> e.g.
>
> my $text = "Hello 1234, come in";
> if ($text =~ /\d{4,4}/)
> {
> #grab just the 4 digit number
> }
>
> thanks
>
>
if ( $text =~ /(\d{4,4})/ )
{
print "captured $1\n";
}
parens around what you want to capture, and each paren group is from
left to right, stuffed in $1, $2, $3, etc.
see
perldoc perlre
for examples
--
Scott R. Godin | e-mail : [EMAIL PROTECTED]
Laughing Dragon Services | web : http://www.webdragon.net/
It is not necessary to cc: me via e-mail unless you mean to speak off-group.
I read these via nntp.perl.org, so as to get the stuff OUT of my mailbox. :-)
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]