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 splitting 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

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -