in reply to Regular Expression - print out certain sections of line based on the content
Having said that, this may do something like what you're after (untested code alert)..
my @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 (@strings) { print $1 if /ENV\(([^)]*)\) STATUS\(Not Running\)/; print $1,$2 if /^PRINT NAME FIRST\(([^)]*)\).* PHONE\([^)]*\)/; }
Update:
Modded RE (to remove space after 'FIRST' - thanx to ww.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regular Expression - print out certain sections of line based on the content
by ww (Archbishop) on Jan 02, 2009 at 17:23 UTC | |
|
Re^2: Regular Expression - print out certain sections of line based on the content
by jas999 (Initiate) on Jan 02, 2009 at 16:21 UTC |