develooper Front page | perl.beginners | Postings from February 2002

Re: Reg Exp help

Thread Previous | Thread Next
Jeff 'japhy' Pinyan
February 26, 2002 06:56
Re: Reg Exp help
Message ID:
On Feb 26, Busse, Rich said:

>	$Out = `$Cmd` ;
>The output always looks like:
>List of Templates and Template Groups assigned to '':
>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:

    ^        # 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
RPI Acacia brother #734
** 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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About