regex - Extract word before the 1st occurrence of a special string -
i have array contains elements like
@array=("link_dm &&& drv_ena&&&1", "txp_n_los|rx_n_lost", "eof &&& 2 &&& length =!!!drv!!!0");
i want characters before first "&&&", , if element doesn't have "&&&", need extract entire element.
this want extract:
likn_dm
txp_n_los|rx_n_lost
eof
i used
foreach $row (@array){ if($row =~ /^(.*)\&{3}/){ push @firstelements,$1; } }
but i'm getting
link_dm &&& drv_ena
txp_n_los|rx_n_lost
eof &&& 2
can please suggest how can achieve this?
perhaps split
ting helpful:
use strict; use warnings; @array = ( "link_dm &&& drv_ena&&&1", "txp_n_los|rx_n_lost", "eof &&& 2 &&& length =!!!drv!!!0" ); foreach $row (@array){ ($chars) = split /\&{3}/, $row, 2; print $chars, "\n" }
output:
link_dm txp_n_los|rx_n_lost eof
Comments
Post a Comment