Front page | perl.beginners |
Postings from February 2002
Re: Reg Exp help
Thread Previous
|
Thread Next
From:
Jeff 'japhy' Pinyan
Date:
February 26, 2002 06:56
Subject:
Re: Reg Exp help
Message ID:
Pine.GSO.4.21.0202260954060.19152-100000@crusoe.crusoe.net
On Feb 26, Busse, Rich said:
> $Out = `$Cmd` ;
>
>The output always looks like:
>
>List of Templates and Template Groups assigned to 'somenode.us.dnb.com':
>====================================================================
>|GRP| SBS-DSM
>====================================================================
>Operation successfully completed.
>
>It's always on 5 separate lines. How do I extract what follows |GRP| on the
>third line to a variable? TIA...
You could use this:
($text) = `$Cmd` =~ /^\|GRP\|\s*(.*)/m;
Let me expand that regex for you:
m{
^ # the start of a "line"
\|GRP\| # the text '|GRP'
\s* # any whitespace following it
(.*) # the rest of the line (non-newline characters)
}m # make ^ match at the beginning of a "line"
You could also use
`$Cmd` =~ /\n\|GRP\|\s*(.*)/;
which works almost exactly the same way.
Or, if you know it'll always be the third line...
($text) = (`$Cmd`)[2] =~ /\|GRP\|\s*(.*)/;
--
Jeff "japhy" Pinyan japhy@pobox.com 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 **
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]
Thread Previous
|
Thread Next