in reply to Regular Expression - print out certain sections of line based on the content

Can you show us the code you have tried and actual output you get? Try making a small chunk of code the reproduces your problem. Otherwise, the best we can suggest (other than writing it for you - I am available for consulting, BTW) is to look at line 42.

--MidLifeXis

  • Comment on Re: Regular Expression - print out certain sections of line based on the content

Replies are listed 'Best First'.
Re^2: Regular Expression - print out certain sections of line based on the content
by gasho (Beadle) on Jan 02, 2009 at 15:27 UTC
    Slightly modified and tested
    @strings = ( "ENV(ABCD1234) STATUS(Running)", "ENV(IJK1234) STATUS(Not Running)", "PRINT NAME FIRST(ABCD) SECOND(EFGH) ADDRESS('') PHONE(12345678)", "PRINT NAME FIRST() SECOND(WXYD) ADDRESS('') PHONE(87654321)" ); foreach $line (@strings){ if ($line=~/ENV\((.*?)\) STATUS\(Not Running\)/){ print "$1\n"; } if ($line=~/PRINT NAME FIRST\((.*?)\) SECOND\((.*?)\) ADDRESS\ +((.*?)\) PHONE\((.*?)\)/){ print "$1 $4\n"; } }
    (: Life is short enjoy it :)